我創建了一個簡單的程序,我想用字符串數組中的其他字符替換一些字符。我創建了一個包含某些字詞的字符串數組,我想循環每個單詞並檢查如果它包含了一些字符,但是當我試圖取代什麼也沒有發生 這裏是我的代碼替換字符串中的字符
string x = "";
x = "Script friends above about type=text/javascript>BBC.adverts.writeleaderboardtrue) all </script>friends,eating,khaled,khaled,khaled";
char[] delimiterChars = { ' ', ',', '.', ':', '\t', ':', '$', '=', ';', '<', '>', '!', ';', ']', '[', '"',
'/','=','-','?'};
string[] words = x.Split(delimiterChars);
for (int j = 0; j < words.Length; j++)
{
words[j] = words[j].ToLower();
}
for (int i = 0; i < words.Length; i++)
{
for (int j = 0; j < words[j].Length; j++)
{
if (words[i][j]=='a'||words[i][j]=='e'||words[i][j]=='i'||words[i][j]=='o'||words[i][j]=='u'
||words[i][j]=='h'||words[i][j]=='w'||words[i][j]=='y')
{
words[i].Replace(words[i][j],'0');
}
else if (words[i][j] == 'b' || words[i][j] == 'f' || words[i][j] == 'p' || words[i][j] == 'v')
{
words[i].Replace(words[i][j], '1');
}
else if (words[i][j] == 'c' || words[i][j] == 'g' || words[i][j] == 'j' || words[i][j] == 'k'
|| words[i][j] == 'q' || words[i][j] == 's' || words[i][j] == 'x' || words[i][j] == 'z')
{
char xx = words[i][j];
words[i].Replace(xx, '2');
Console.WriteLine(words[i]);
}
else if (words[i][j] == 'd' || words[i][j] == 't')
{
words[i].Replace(words[i][j], '3');
}
else if (words[i][j] == 'l')
{
words[i].Replace(words[i][j], '4');
}
else if (words[i][j] == 'm' || words[i][j] == 'n')
{
words[i].Replace(words[i][j], '5');
}
else if (words[i][j] == 'r')
{
words[i].Replace(words[i][j], '6');
}
}
}