aspose file tools*
The moose likes Beginning Java and the fly likes breaking string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "breaking string" Watch "breaking string" New topic
Author

breaking string

N Naresh
Ranch Hand

Joined: Nov 04, 2008
Posts: 66
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

Joined: Aug 11, 2006
Posts: 19
Hi Nimmala,

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

Regards
Hari
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3689
    
  16
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.


Joanne
N Naresh
Ranch Hand

Joined: Nov 04, 2008
Posts: 66
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

Joined: Oct 13, 2005
Posts: 39436
    
  28
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

Joined: Nov 04, 2008
Posts: 66
hi could you give me small example so that i will understand in a better way
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
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

Joined: Nov 03, 2008
Posts: 48
Have a look at the Scanner API

And Regex
[ November 05, 2008: Message edited by: Rory Marquis ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: breaking string