String split in java
I have String
like:
Start:Monday, August 15, 2011 8:00am (Eastern Standard Time)End:Monday开发者_开发百科, August 15, 2011 9:00am (Eastern Standard Time)Where:Who:Description:
I want to split it like this:
Start : (newline)
End: (newline)
Where: (newline)
Who: (newline)
Description: (newline)
Mind that :
after start and each tag value change it dynamically, so please give me a dynamical solution
By using the below code you can get your string like:
Start:Monday, August 15, 2011 8-00am (Eastern Standard Time)End:Monday, August 15, 2011 9-00am
then you can use String.split("separator")
String strTest="Start:Monday, August 15, 2011 8:00am (Eastern Standard Time)End:Monday, August 15, 2011 9:00am ";
StringBuilder builderString = new StringBuilder(strTest);
for (int i = 0; i < builderString.length(); i++) {
if(builderString.charAt(i)==':'){
if(Character.isDigit(builderString.charAt(i-1))){
builderString.setCharAt(i, '-');
}
}
}
strTest=builderString.toString();
System.out.println(strTest);
精彩评论