2 回答

TA貢獻1943條經驗 獲得超7個贊
嘗試對 Unicode大寫字母使用正則表達式\p{Lu}
using System.Text.RegularExpressions;
...
// Let's remove 2 or more consequent capital letters
int X = 2;
// English and Russian
string source = "NICEWEather - ХОРОшая ПОГОда - Keep It (HAPpyhour)";
// ather - шая да - Keep It (pyhour)
string result = Regex.Replace(source, @"\p{Lu}{" + X.ToString() + ",}", "");
這里我們使用\p{Lu}{2,}模式:大寫字母出現X(2在上面的代碼中)或更多次。

TA貢獻1860條經驗 獲得超9個贊
從字符串中刪除大寫字母
string str = " NICEWEather";
Regex pattern = new Regex("[^a-z]");
string result = pattern.Replace(str, "");
Console.WriteLine(result );
輸出: ather
如果按順序多次出現,則刪除大寫字母,然后試試這個
string str = " NICEWEather";
Regex pattern = new Regex(@"\p{Lu}{2,}");
string output = pattern.Replace(str, "");
Console.WriteLine(output);
- 2 回答
- 0 關注
- 226 瀏覽
添加回答
舉報