字符串拆分的用例

时间:2013-09-03 07:36:47

标签: regex split apache-stringutils

我希望代码段能够拆分以下字符串:

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

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

我现在不想使用indexof, StringUtils 还是正则表达式可以帮助我?我正在寻找StringUtilus,但我没有得到任何东西。感谢您的意见。

3 个答案:

答案 0 :(得分:1)

这应该足够了:

inputStr.split("(?=\band\b)")

答案 1 :(得分:1)

如果您在php中尝试,请尝试

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

答案 2 :(得分:1)

我得到了,我们可以使用

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

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