Interchanging String using RegularExpression
This Example describe the way to split a String and interchange the index of string using Regularexpression. The steps involved in interchanging a String are described below:String parg = "For some college -Presidents want law- revisited saying age limit- has not curbed-that problems on campuses":- Defines a string that is to be splitted after (-) expression.
String[] token = null:-Declares an array named token in which the splitted string is to be stored.
String splitPoint = "-":-Declares the point from where the string is to be splitted.
sentence.split(splitPoint):-This method splits the string from the point where it finds (-)expression.
retival = token[1] + " " + token[0] +""+ token[4] +""+ token[3]:-This method is generally for the displaying tokens in the order which you want.
SplittingString_Interchanging.java
|
Output of the program
BEFORE SPLITTING: For some college -Presidents want
law- revisited saying age limit- has not curbed-that problems on campuses ============================================ AFTER SPLITTING: Presidents want law For some college that problems on campuses has not curbed |
Download Source code