hi,

i think it has to do with the multiline flag. that causes it to eat the newline (read the javadocs).  i don't see any neat way to do it, other than treating whitespace and newlines separately. for example, something lime

        String s1 = "hello\n  hello\n\n    hello\n hi\n";
        Pattern p = Pattern.compile("^[ \t]+|[ \t]+$|\n$", Pattern.MULTILINE);
        Matcher m = p.matcher(s1);
        s1 = m.replaceAll("");


On 10/23/09 9:16 AM, jax wrote:
I am trying to strip all whitespace from "each line" in a EditText
View.  The _expression_ I am using is this

String result =	Pattern.compile("^\\s+|\\s+$",
Pattern.MULTILINE).matcher(input).replaceAll("");

This works for the following input

------------------------
hello
      hello
   hello
 hi
------------------------
This will produce:
hello
hello
hello
hi


but
------------------------
hello
      hello

   hello
 hi
------------------------
will produce:
hello
hellohello
hi

Notice the new line (\n).  This is causing the problem.  What I want
is:
hello
hello
hello
hi

Any ideas about how to fix this?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

  

--

Reply via email to