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];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.