[英]replacing multiple words in a string with multiple words
所以我想做的是我有一個清單
List<string> words = new List<string>();
words.AddRange(new string[]{ "list of words", "i want to replace" })
現在我想從文本框中獲取文本並從列表“單詞”中搜索單詞並將它們全部替換為與它們相同的文本+某些內容,對不起,如果這令人困惑或解釋不善,但我已盡力而為,謝謝所有的幫助! :D
如果我理解正確,您希望實現以下目標:
string textboxString = "Text from Textbox";
List<string> words = new List<string>();
words.Add("Text");
foreach(string word in words)
{
textboxString = textboxString.Replace(word, word + " + something");
}
您也可以使用Regex.Replace();
我理解你的問題的方式你想在某些詞中添加一些東西。 如果您希望根據單詞更改某些內容,您將需要一個字典(嗯……需要是一個強詞)
string textboxString = "Text from Textbox";
Dictionary<string, string> words = new Dictionary<string, string>();
words.Add("Text", "Something");
words.Add("from", "SomethingElse");
foreach (var key in words)
textboxString = textboxString.Replace(key.Key, key.Key + key.Value);
這應該給你:
"TextSomething fromSomethingElse TextSomethingbox"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.