且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从Mainstring C#中获取标记内的子字符串

更新时间:2023-11-03 13:34:34

当然,没有循环。请参阅:

http:// msdn。 microsoft.com/en-us/library/ms131448(v=vs.110).aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/tabh47cf(v = vs.110)的.aspx [ ^ ],

http://msdn.microsoft.com/ en-us / library / kwb0bwyd(v = vs.110).aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/k8b1470s(v=vs.110).aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/hxthx5h6(ⅴ = vs.110).aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/aka44szs(v = vs.110).aspx [ ^ ]。



http://msdn.microsoft .com / zh-CN / library / system.text.regularexpressions.regex%28v = vs.110%29.aspx [ ^ ]。



-SA
Of course, no loops. Please see:
http://msdn.microsoft.com/en-us/library/ms131448(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/tabh47cf(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/kwb0bwyd(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/k8b1470s(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/hxthx5h6(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/aka44szs(v=vs.110).aspx[^].

Or http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex%28v=vs.110%29.aspx[^].

—SA


您可以使用以下函数..



You can use following function..

string GetMiddleString(string input, string firsttoken, string lasttoken)
{
    int pos1 = input.IndexOf(firsttoken) + 1;
    int pos2 = input.IndexOf(lasttoken);
    string result = input.Substring(pos1 , pos2 - pos1);
    return result
}







http://***.com/a/2449659 [ ^ ]


试用此代码..



工作正常..







Try this code..

works fine..



string input = "[fconsender]Username (11:00 AM):[/fconsender] Hi Good Afternoon!";
           string starttag = "[fconsender]";
           string endtag = "[/fconsender]";
           int sindex = input.IndexOf(starttag) + starttag.Length;
           int length = input.IndexOf(endtag) - starttag.Length;
           string output = input.Substring(sindex, length);