开发者

Splitting a String with a Regular Expression

I'm trying to split a string with a regular expression. But it is not working开发者_如何学编程, the content is going all to the first array position of the string array. Isn't this correct?:

scanResult is not relevant, just a simple string.

StringBuffer scanList = new StringBuffer();
for cycle{
    scanList.append("SPl"+scanResult.SSID+"ID:"+scanResult.BSSID);
}
String result=scanList.toString();
String[] actual=result.split("SP1");


"SPl" is not the same as "SP1". You are using a lower-case L in the first String and the number 1 in the second string.

I would also update you append String to append all the values. It is usually better to do something similar to the following:

sb.append(val1).append(val2).append(val3).append(val4);


It seems that in your append, you have SPl (S-P-lowercase l) and in the split, you have SP1 (S-P-One)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜