0

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 '@@@'.

Sar
  • 550
  • 4
  • 18

4 Answers4

0

try this:

String patternString = "@@@";
Pattern pattern = Pattern.compile(patternString);
String[] split = pattern.split(text);
Xenione
  • 2,174
  • 1
  • 23
  • 30
0

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.

gkrls
  • 2,618
  • 2
  • 15
  • 29
0

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!

Krupa Patel
  • 3,309
  • 3
  • 23
  • 28
0

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"
Elango
  • 412
  • 4
  • 24