3

I want code snippet for splitting the below string:

Input : select * from table where a=? and b=? and c=?

Output: 
    Str1: select * from table where a=?
    Str2: and b=? 
    Str3: and c=?

I do not want to use indexof as of now, whether StringUtils or regex can help me here? I was looking for StringUtilus but I did not get anything in it. Your input is appreciated.

m-oliv
  • 419
  • 11
  • 27
Rahul
  • 41
  • 2

3 Answers3

1

This should suffice:

inputStr.split("(?=\band\b)")
Amadan
  • 191,408
  • 23
  • 240
  • 301
1

If you are trying it in php then try ,

$myvar = explode('and','select * from table where a=? and b=? and c=? ');
$str1 = $myvar[0];
$str2 = $myvar[1];
$str3 = $myvar[2];
yantrakaar
  • 374
  • 3
  • 15
1

I got, we can use

    String str = "select * from table where a=? and b=? anc c=?";
    String[] tokens = str.split("\\?");

    for (String string : tokens) {
        System.out.print("tokens: "+string);
    }
Rahul
  • 41
  • 2