需要得到一个"后的字符串;字QUOT;在C#中的字符串 [英] Need to get a string after a "word" in a string in c#
本文介绍了需要得到一个"后的字符串;字QUOT;在C#中的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到在C#中的字符串,我有字符串中查找特定的单词代码,并必须得到单词码后剩余的字符串。
的字符串是
错误描述,代码:-1
块引用>
所以我必须找到在上面的串词的代码,我必须得到错误代码。
我已经看到了正则表达式,但现在明确的理解。有没有简单的方法
解决方案字符串tobesearched =代码:?
串码= myString.Substring(myString.IndexOf(tobesearched)+ tobesearched.Length);
这样呢?
也许你应处理失踪
代码的情况:
...字符串tobesearched =代码:
INT九= myString.IndexOf(tobesearched);
如果(!九= -1)
{
串码= myString.Substring(IX + tobesearched.Length);
//做的东西在这里
}
i'm having a string in c# for which i have to find a specific word "code" in the string and have to get the remaining string after the word "code".
The string is
"Error description, code : -1"
so i have to find the word code in the above string and i have to get the error code. I have seen regex but now clearly understood. Is there any simple way ?
解决方案string tobesearched = "code : " string code = myString.Substring(myString.IndexOf(tobesearched) + tobesearched.Length);
Something like this?
Perhaps you should handle the case of missing
code :
...string tobesearched = "code : " int ix = myString.IndexOf(tobesearched); if (ix != -1) { string code = myString.Substring(ix + tobesearched.Length); // do something here }
这篇关于需要得到一个"后的字符串;字QUOT;在C#中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文