• Post Reply Bookmark Topic Watch Topic
  • New Topic

Truncate and display only specific character length  RSS feed

 
Rithanya Laxmi
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have an error message which 800 characters long I want to truncate and display only 300 characters and store the 300 characters in the DB table as the column size is of 300 characters. How to get only first 300 characters from the string? Please clarify.

Thanks.
 
Anayonkar Shivalkar
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

You may check substring method of String class.

However, in practice, it is not a good idea to pick partial text from error message - what if there is some important data in those discarded 500 chars? Maybe you need to increase column length.
 
Raymond Tong
Ranch Hand
Posts: 255
2
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rithanya Laxmi wrote:Hi,

I have an error message which 800 characters long I want to truncate and display only 300 characters and store the 300 characters in the DB table as the column size is of 300 characters. How to get only first 300 characters from the string? Please clarify.

Thanks.

http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#substring(int)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!