Regular expressions help

by jax » Sat, 24 Oct 2009 00:17:38 GMT


Sponsored Links
 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?

--~--~---------~--~----~------------~-------~--~----~



Regular expressions help

by jax » Sat, 24 Oct 2009 11:15:16 GMT


 ok thanks,

as I understand \s matches all whitespace characters as there are some
extra unicode whitespace characters in other languages (not part of
ASCII).  Maybe it is not worth worrying about these characters though.

I will try you solution above.



On Oct 23, 11:40pm, Jeffrey Blattman <jeffrey.blatt...@gmail.com>



--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Other Threads

1. Black screen when playing a streaming video

Hi there,
my platform is android 2.1, I face the following problem:
I go to http://3g.youku.com and wath the streaming video (176*144
res.), most time, only audio is played.
I catch the log and find one key log info:

E/SurfaceFlinger( 1204): LayerBuffer::BufferSource::postBuffer()
invalid buffer (offset=819200, size=-1127995968, heap-size=6934528

by debuging, I get the relative information in LayerBuffer is that:
buffers.w=176, buffers.h=144, buffers.hor_stride=1732440432,
buffers.ver_stride=1732440408
and mBufferSize = -1127995968.

I dont know why the attribute buffers.hor_stride and
buffers.ver_stride so strange, can anybody explain this?

thanks,
ever

-- 

2. Multitasking on Android - Why So Incredibly Bad?

What phone are you using? I do that stuff on my HTC Magic everyday, no
issues. (Android 1.5 FTW? ;-)




> 

3. struct proto in /net/ipv4/tcp_ipv4.c

4. The $50,000 Android Phone

5. Handle GONE in RelativeLayout

6. Help need for writing the asound.conf file Sigma 8654

7. Logitech Harmony Link Turns Your Phone Into the Ultimate Remote