考慮以下字符串:如何修剪字符串中某些圖案字符的字符?
string s = "I need drop the 1 from the end of AAAAAAAA1 and BBBBBBBB1"
我如何從一個1結尾的8字符串修剪「1」?我到目前爲止找到一個工作正則表達式模式,發現這些字符串,我猜我可以使用TrimEnd刪除「1」,但我該如何修改字符串本身?
Regex regex = new Regex("\\w{8}1");
foreach (Match match in regex.Matches(s))
{
MessageBox.Show(match.Value.TrimEnd('1'));
}
我正在尋找將是「我需要從AAAAAAAA和BBBBBBBB年底下降了1」
執行八個字符必須是相同的? –
如果您有正則表達式來查找需要刪除的字符,請使用Regex.Replace:http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex.replace.aspx – mbeckish
如果它是任何8個字符的字符串,爲什麼你需要正則表達式,除非你的意思是子串? – DGibbs