试图找出一种方法来获取字符串中两个可预测元素之间的文本(包括)。
例子:
完整字符串 = [http:Something] One Two Three [http:AnotherOne] Four [http:BlahBlah] sdksaod,cne 9ofew {}@:P{
理想结果:
字符串 1 = [http:Something] One Two Three
字符串 2 = [http:AnotherOne] Four
字符串 3 = [http:BlahBlah] sdksaod,cne 9ofew {}@:P{
目前我可以得到结果,但它非常混乱,以后可能更难更新。有没有更好的方法来做到这一点?
当前代码示例:
String par = "[http//blah.com] One Two Three [http://wow.com] Four Five
[http://another.com] Six";
String[] paramUrls = par.Split(' ');
List<String> paramPerURL = new List<String>();
String temp = "";
Boolean found = false;
for(int z = 0; z < paramUrls.Length; z++){
if(paramUrls[z].Contains("[http")){
if(found){
paramPerURL.Add(temp);
}
found = true;
temp = paramUrls[z] + " ";
} else{
temp += paramUrls[z] + " ";
}
if(z == paramUrls.Length -1){
paramPerURL.Add(temp);
}
}
收到一只叮咚
相关分类