• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

breaking string

 
N Naresh
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi i want to break a string after a certain number of characters that is containing <br> \r\n and html tags how we can achieve this.
 
Hari Kumarkar
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nimmala,

If you don't mind, I did'nt get you, can you brief about your question.

Regards
Hari
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by NimmalaN NareshN:
hi i want to break a string after a certain number of characters that is containing <br> \r\n and html tags how we can achieve this.


I'm not quite sure what you're asking but are the String.substring() or String.split() methods what you want ? If not can you perhaps give an example of the string you start with and what you want to end up with.
 
N Naresh
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have string like this
<!--
################################################################
Modifications may have been made to this file by SunGard Higher Education.
Specific tags have been modified to prevent malicious scripts
from running or to prevent display problems. The following
tags may have been used to replace existing tags in this file
and can be restored to their original state by removing the 'x':
xBASE, xSCRIPT, xSTYLE, xLINK, xMETA
################################################################
-->
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ

----------------<BR><m><b>ddss


i want to break this string after 72(A....Z characters) characters per each line and make them to display in separate line in the browser.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49818
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about putting the String into a StringBuilder? You can find the indices of line end characters, and insert line ends 72 places later.
There is probably a Character class method which tells you whether a char is line end.
By the way, you might get better platform independence by going through the properties with System.getProperties to find the correct names, then System.getProperty("line.end") to get the platform-specific String for "\n" or "\r" or "\r\n".
 
N Naresh
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi could you give me small example so that i will understand in a better way
 
Campbell Ritchie
Sheriff
Pie
Posts: 49818
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
StringBuilder builder = new StringBuilder(string);
int index = builder.indexOf("\n");
builder.insert(index + 72, "\n");


You will need to check that carefully against the API because I have probably got all the method names wrong.
 
Rory Marquis
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at the Scanner API

And Regex
[ November 05, 2008: Message edited by: Rory Marquis ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic