当前位置: 动力学知识库 > 问答 > 编程问答 >

c# Regex more than one word

问题描述:

I have a text for example , Nim-Qloth, Iceberg, Szatan Krul, Consequence, Arithael, and I use regex to find text between , , I have that code

using (StreamReader sr = new StreamReader(miejscepliku))

{

String line = sr.ReadToEnd();

String odbiorca = Regex.Match(line, @"\, ([^,]*)\,").Groups[1].Value;

textBox3.Text = odbiorca;

}

My code find one word and word is showing in textbox3 word is "Nim-Qloth" but i want click second time and find next word ex. "Iceberg". How do that?

网友答案:

String.Split is sufficient and more efficient:

String[] odbiorca = line.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

You can access an array by index(zero based). You just need to store the current index so that you can show the next on each button-click.

private int currentIndex = -1; // a field in your class

...

if(++currentIndex == odbiorca.Length) currentIndex = 0;
string currentWord = odbiorca[currentIndex];
分享给朋友:
您可能感兴趣的文章:
随机阅读: