3

我想要用于拆分以下字符串的代码片段:

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

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

我现在不想使用 indexof,StringUtils或 regex 是否可以在这里帮助我?我在寻找 StringUtilus 但我没有得到任何东西。感谢您的意见。

4

3 回答 3

1

这应该足够了:

inputStr.split("(?=\band\b)")
于 2013-09-03T07:41:35.303 回答
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);
    }
于 2013-09-03T08:12:22.537 回答
1

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

$myvar = explode('and','select * from table where a=? and b=? and c=? ');
$str1 = $myvar[0];
$str2 = $myvar[1];
$str3 = $myvar[2];
于 2013-09-03T07:43:39.747 回答