I have data with repeating pattern '@@@'.I want to extract all strings between this pattern. The data is like -
son@@@can@@@e@@@nick@@@54@@@
how can i get all data between the pattern '@@@'.
I have data with repeating pattern '@@@'.I want to extract all strings between this pattern. The data is like -
son@@@can@@@e@@@nick@@@54@@@
how can i get all data between the pattern '@@@'.
try this:
String patternString = "@@@";
Pattern pattern = Pattern.compile(patternString);
String[] split = pattern.split(text);
You can use Scanner
with "@@@"
delimiter.
Scanner in = new Scanner("son@@@can@@@e@@@nick@@@54@@@");
in.useDelimiter("@@@");
while(in.hasNext)
String x = in.next();
//Do something with x;
x
will hold everything between @@@
. You can easily store them in an Array
inside the loop or use them anyway you like.
Try this:
String str = "son@@@can@@@e@@@nick@@@54@@@";
String newStr = str.replaceAll("[@]+", "");
or you can separate all world via
String rem = "@@@";
Pattern pattern = Pattern.compile(rem);
String[] splitarr = pattern.split(text);
for(int i=0;i<aplitarr.length();i++)
{
String word=aplitarr[i].ToString();
}
Hope this may help you!
try,
String[] separated = CurrentString.split("@@@");
separated[0]; // this will contain "son"
separated[1]; // this will contain "can"
or
StringTokenizer tokens = new StringTokenizer(CurrentString, "@@@");
String first = tokens.nextToken();// this will contain "son"
String second = tokens.nextToken();// this will contain "can"