![](/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.