如何在字符串后获得下一个分号?

时间:2014-11-05 07:09:16

标签: c# string search

假设我在文本框中有以下行:

   I am unable to
             find the next semicolon;
   I need your help;

可能有\n,也可能没有。{/ p>

我需要在字符串";"之后得到下一个分号,即"unable"

我该如何解决?

2 个答案:

答案 0 :(得分:0)

var idx = yourString.IndexOf("unable");
if (idx != -1)
{
    idx = yourString.IndexOf(';', idx);
    if (idx != -1)
    {
        // you found it
    }
}

http://msdn.microsoft.com/en-us/library/5xkyx09y(v=vs.110).aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1

答案 1 :(得分:-2)

可能的解决方案:

private const string UNABLE = "unable";
var index = yourTextBoxString.IndexOf(UNABLE);
if(index != -1)
{
    index = yourTextBoxString.IndexOf(";", index + UNABLE.Lengh)
    if(index != -1)
    //found it, do something
}