I need to split my String by spaces. For this I tried:
str = \"Hello I\'m your String\";
String[] splited = str.split(\" \");
But it doesn\
Here is a method to trim a String that has a "," or white space
private String shorterName(String s){
String[] sArr = s.split("\\,|\\s+");
String output = sArr[0];
return output;
}
Very Simple Example below:
Hope it helps.
String str = "Hello I'm your String";
String[] splited = str.split(" ");
var splited = str.split(" ");
var splited1=splited[0]; //Hello
var splited2=splited[1]; //I'm
var splited3=splited[2]; //your
var splited4=splited[3]; //String
Try
String[] splited = str.split("\\s");
http://download.oracle.com/javase/tutorial/essential/regex/pre_char_classes.html