Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

breaking string

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 74354
334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi could you give me small example so that i will understand in a better way
 
Campbell Ritchie
Marshal
Posts: 74354
334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have a look at the Scanner API

And Regex
[ November 05, 2008: Message edited by: Rory Marquis ]
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic