| Author |
problem in string's split method
|
ganesh pol
Ranch Hand
Joined: Apr 29, 2005
Posts: 151
|
|
String st="172.12.23.23"; 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: 3652
|
|
|
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.
|
 |
 |
|
|
subject: problem in string's split method
|
|
|