aspose file tools*
The moose likes Beginning Java and the fly likes problem in string's split method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "problem in string Watch "problem in string New topic

problem in string's split method

ganesh pol
Ranch Hand

Joined: Apr 29, 2005
Posts: 151
String st="";
String [] st1=st.split(".");
System.out.println("string split ="+st1.length );

above code gives me empty array of String how to change my regex expression i.e "."

so that this method will give give me array with 4 elements=172,12,23,23
Rusty Shackleford
Ranch Hand

Joined: Jan 03, 2006
Posts: 490
Try putting \\ in front of . : "\\."

"Computer science is no more about computers than astronomy is about telescopes" - Edsger Dijkstra
Rudy Rusli
Ranch Hand

Joined: Jun 01, 2006
Posts: 114
This would also work:
String [] st1=st.split("[.]");
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3704

You might be thinking of StringTokenizer which can split a string into tokens based on a single value like a "."

My Blog: Down Home Country Coding with Scott Selikoff
Rusty Shackleford
Ranch Hand

Joined: Jan 03, 2006
Posts: 490
Stick with String.split(), it works great and besides StringTokenizer is a legacy class kept around to not break old code, but shouldn't be used on new code.
I agree. Here's the link:
subject: problem in string's split method