请教一个分割字符串的问题 以5678开头并以abcd结束的字符串的分割问题56780000hfaihfaabcd,可以分割为0000hfaihfa但是如果5678前面有字符且不是abcd的就不分割,该如何做呢?如56781335678dsfadfabcd,就分割为1335678dsfadf,而不是分割为133和dsfadf请教一个最快的算法。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 string s = "56781335678dsfadfabcd";if (s.StartsWith("5678")) s = "abcd" + s;if (s.EndsWith("abcd")) s = s + "5678";string[] result = s.Split(new string[] { "abcd5678" }, StringSplitOptions.RemoveEmptyEntries); public string GetNewString(string str){ while(str.StartWith("5678") && str.EndWith("abcd")) //5678开头,abcd结尾 { str=str.Substring(4,str.Length-8); while(str.StartWith("abcd5678")) //abcd5678开头 { str=str.Substring(8); } } retur str; } C# 声音控制控件问题 关于正则表达式 如何选出表中指定字段不能转换成指定类型的记录 怎么把数据库的某一条记录保存到记事本 这个错误:xxx.exe-Common Language Runtime Debugging Services 甘特图控件 PlexityHide.GTP.NET 如何注册? winform中嵌入WORD或EXCEL,谁有例程?(至少100分) 急,请大家帮忙修改一个正则表达式 如何用C#开发带附件发送的smtp服务器? 在C#里怎样强行中止一个线程 做本地数据缓存 本地数据库是相对路径时无法获取远程数据库数据,使用绝对地址则可以,这是什么原因 Unity 通信問題
if (s.StartsWith("5678")) s = "abcd" + s;
if (s.EndsWith("abcd")) s = s + "5678";
string[] result = s.Split(new string[] { "abcd5678" }, StringSplitOptions.RemoveEmptyEntries);
{
while(str.StartWith("5678") && str.EndWith("abcd")) //5678开头,abcd结尾
{
str=str.Substring(4,str.Length-8);
while(str.StartWith("abcd5678")) //abcd5678开头
{
str=str.Substring(8);
}
}
retur str;
}