aspose file tools*
The moose likes Java in General and the fly likes String.split() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "String.split()" Watch "String.split()" New topic
Author

String.split()

adeeb alexander
Ranch Hand

Joined: May 29, 2008
Posts: 268
Hi all
Consider the String str = "WHAT is YOUR name;

now i am unable to split("your");

I need a way to use split without case sensitivity. Anybody can help.


Thanks alexander
Rok Štelcer
Ranch Hand

Joined: Nov 03, 2009
Posts: 101
Just a hint .... split method accepts a regex.


SCJP, SCWCD
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

Check out the Javadoc of java.util.regex.Pattern. It mentions flags for case insensitive.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
adeeb alexander
Ranch Hand

Joined: May 29, 2008
Posts: 268
Thanks for your help all.

I used the following. String[] spl=str.split("\\p{Lower}your");

Is this correct. I am not getting the output.

Thanks once again.
adeeb alexander
Ranch Hand

Joined: May 29, 2008
Posts: 268
Hi all.
I have used this, String[] spl=str.split("[your,YOUR]");

This working partially for me. It can split even if i give YOUR as your or Your or YouR. The problem is that it splits even is i give YOU (in any case). This is the drawback.

Help me out a little please.

Thanks and Regards
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
adeeb alexander wrote:Hi all.
I have used this, String[] spl=str.split("[your,YOUR]");

This working partially for me. It can split even if i give YOUR as your or Your or YouR. The problem is that it splits even is i give YOU (in any case). This is the drawback.

Help me out a little please.

Thanks and Regards


You really want to read through the regex tutorial because what you've got up there isn't even close to what you want. Please check out these two tutorials, the first for the basics, the latter for the more advanced:

Sun's basic regex tutorial
Excellent more advanced regex tutorial

in that last tutorial, you'll want to especially have a look at this page (hint, hint):
page with your answer
adeeb alexander
Ranch Hand

Joined: May 29, 2008
Posts: 268
Thanks a lot pete.

That really helped me.
I used the following. String[] spl=str.split("(?i)your");

I thought of learning regex at once. I think this really takes some time and experience. Anyways thanks again.

Thanks
alexander
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
adeeb alexander wrote:Thanks a lot pete.

That really helped me.
I used the following. String[] spl=str.split("(?i)your");


You're quite welcome. The regex I used was similar to yours above but also got rid of white space if it exists:

(corrections from any regex guru is most welcome!).

I thought of learning regex at once. I think this really takes some time and experience.

It seems that nowadays, if you do any Java programming, regex is becoming indispensable, and if you're going to use it, you'd might as well learn it. I'm at the stage now where I can write regex code only when I have a nearby browser window open to one or the other tutorial. I am hopeful that in time this will improve.

Cheers!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String.split()