Saturday 15 May 2010

java - Replace newline with and spaces with inside tags -


I would like to change Newline and location with my counterparts so that they can style correctly in my Android app.

I would like to know the best way to get this regex I & lt; Br / & gt; :

  has tried to do this to replace Newline with string.replaceAll ("@ . * \\ n * * Lt; / Code & gt; @si "," 

But it was not working

So what I want to achieve:

to \ n < / Code> to & lt; Br / & gt; , and "double unloaded space" from & amp; Emsp; .

You can do this in Java call 2:

 < Code> string = string.replaceAll ("\\ r? \\ n", " & quot;); String = string Location ("", "& amp; emsp;"); Edit   

:
  Matcher m = Pattern.compile ("(? S) (? I) (? & Lt; = & lt; code & Gt;) (?? +) (= & Lt;? / Code & gt ;.) ") matching (string); Stringbuffer buff = new stringbuffer (); While (m.find ()) {string grp = m.group (1) .replaceAll ("\\ r? \\ n", "

I have used the string # replaced in the second call with purpose because we actually do not have any regex Are not used. / P>

In addition to this, @ AMN has commented that you have your string gt; and tags and can avoid these replacements.

No comments:

Post a Comment