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. Apple blocks 'Newber' app approval for 6 months

While the Android Market is far from perfection, its good to keep
perspective and be glad that at least there is no bizarrely inconsistent and
lengthy approval process like the App Store has in place:

http://arstechnica.com/apple/news/2009/03/company-halting-iphone-app-work-after-long-approval-delay.ars?utm_source=microblogging&utm_medium=pingfm&utm_term=Main%20Account&utm_campaign=microblogging

"FreedomVoice submitted its Newber application for App Store approval more
than six months ago, but still hasn't heard anything from Apple. Now, the
company has decided to stop development and cuts its losses at $600,000.
Although it's an unfortunate situation, Newber's story is an example of the
risks associated with too much early marketing of App Store applications."

-Josh

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

2. Help with dialog builder and resource problem please

I'm trying to build an alert dialog with a builder.  The code is from
the svn here:

http://code.google.com/p/apps-for-android/source/browse/trunk/DivideAndConquer/src/com/google/android/divideandconquer/Eula.java?r=93

There is also a web site with description of how to use the code here:
http://androiddevstudio.com/tutorials/adding-eula-to-android-app/comment-page-1#comment-16

So far the class successfully runs this code:

...previous code
builder.setPositiveButton(com.mywebsite.MyLib.R.string.eula_accept,
new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which)
{
                    accept(preferences);
                    if (activity instanceof OnEulaAgreedTo) {
                        ((OnEulaAgreedTo) activity).onEulaAgreedTo();
                    }
                }
            });

Then I try to run this code immediately after it:

builder.setNegativeButton(com.mywebsite.MyLib.R.string.eula_refuse,
new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which)
{
                    refuse(activity);
                }
            });

And then I get Force Close.  I've placed several log messages in my
code for debug and I'm fairly certain this is where it hangs up.

The DDMS indicates:

W  535  ResourceType  getEntry failing because entryIndex 3 is beyond
type entryCount 3
W  535  ResourceType  Failure getting entry for 0x7f040003 ( t=3 e=3 )
in package 0: 0x80000001

I have commented out this single builder.setNegativeButton code and
the file runs with no force closure.  I'm also absolutely sure that
both string resources are in the strings.xml file.

You may notice my string designation:

com.mywebsite.MyLib.R.string.eula_accept

This is because I'm trying to access this eula from a reusable library
class.  This is where is gets a little weird.  The title in the dialog
displays this:

"res/raw/button_click.ogg"

And the accept button at the bottom of the dialog displays this text:

"res/raw/instructions.ogg"

Those files are both from the main project itself, in another package,
hence the use of long definitions for the string files.  Unfortunately
it still doesn't access those strings.

I would like to know how to do this correctly, so I can reuse this
library class.  And more importantly, so I can understand what I'm
doing wrong.

I'm using Eclipse and the latest SDK of Android.

Thanks in advance.



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

3. Test UK download

4. Putting Android on Par with the iPhone Software (official continuation)

5. GPRS settings for my developer G1 phone - PAP and CHAP settings

6. How can i find out which version of webkit that android is using

7. <form> post from webview with credentials