![](/img/trans.png)
[英]RegEx to replace more than one hyphen with one hyphen in a string? asp.net C#
[英]c# Regex more than one word
我有一个文本,例如 Nim-Qloth、Iceberg、Szatan Krul、Consequence、Arithael,我使用正则表达式在, ,
之间查找文本, ,
我有那个代码
using (StreamReader sr = new StreamReader(miejscepliku))
{
String line = sr.ReadToEnd();
String odbiorca = Regex.Match(line, @"\, ([^,]*)\,").Groups[1].Value;
textBox3.Text = odbiorca;
}
我的代码找到一个单词,文本textbox3
显示的单词是"Nim-Qloth"
但我想第二次单击并找到下一个单词 ex。 "Iceberg"
。 那怎么办?
String.Split
就足够了,而且效率更高:
String[] odbiorca = line.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
您可以通过索引(从零开始)访问数组。 您只需要存储当前索引,以便您可以在每次单击按钮时显示下一个索引。
private int currentIndex = -1; // a field in your class
...
if(++currentIndex == odbiorca.Length) currentIndex = 0;
string currentWord = odbiorca[currentIndex];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.