分割字符串的问题 分割符为两个,头尾个一个,且不相同,这样的串分割什么方法最快 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 start内容...endstart内容...endstart内容...endstart内容...endstart内容...endstart内容...endstart内容...endstart内容...endstart内容...endstart内容...endstart内容...endstart内容...end就是把start和end中的内容分割出来 string str = "start内容1...endstart内容2...endstart内容3...endstart内容4...endstart内容5...endstart内容6...endstart内容7...endstart内容8...endstart内容9...endstart内容10...endstart内容11...endstart内容12...end"; var s = System.Text.RegularExpressions.Regex.Matches(str, @"start(.*?)end"); foreach (Match mt in s) { Response.Write(mt.Groups[1].Value + "<br/>"); } 用正则取吧@"start(?<内容>[\s\S]*)end" 分组不太懂,不过担心只取最长的一组。即str本身。。var s = System.Text.RegularExpressions.Regex.Matches(str, @"start([^(end).*]?)end"); 字符串.Split(new String[]{"start","end"},选择不保留空串就可以了); 正则这么简单?试一下这个字符串:string s = "start\"this is the end of movie\"endstart\"shall we start the meeting?\"endstart\"strange word: 'endstart'\"end"; 将end替换为start,然后全部就用start分割。 用 string.indexOf方法 我给你总结下: 1、用正则,楼上已经给出了代码。 2、用String.Split();要讲效率的话,个人认为,还是用正则吧! GridView combox绑定数据源后如何遍历 c#读取word表格的问题 多窗体啊,怎么不让它关闭啊 GDI+中如何实现翻转 一个类的属性在get访问器里实现的逻辑是从session里读取值,那么这个属性适合写成静态的吗? 簡單問題,解決就解帖,頂者有分 asp的奇怪问题?(高手解答) 调用MSMQ出错,谁能帮忙? 取得文件所在路径 【疑问】关于从外部给已经启动的程序传值的问题 可以通过程序获得HDD的状态 和 GPU的使用率么?
就是把start和end中的内容分割出来
var s = System.Text.RegularExpressions.Regex.Matches(str, @"start(.*?)end");
foreach (Match mt in s)
{
Response.Write(mt.Groups[1].Value + "<br/>");
}
@"start(?<内容>[\s\S]*)end"
var s = System.Text.RegularExpressions.Regex.Matches(str, @"start([^(end).*]?)end");
1、用正则,楼上已经给出了代码。
2、用String.Split();
要讲效率的话,个人认为,还是用正则吧!