如何在asp.net中替换字符串中的特殊字符

ppp*_*ppp 2 asp.net replace

我的代码 -

txtPhoneWork.Text.Replace("-","");
        txtPhoneWork.Text.Replace("_", "");
        txtMobile.Text.Replace("-", "");
        txtMobile.Text.Replace("_", "");
        txtPhoneOther.Text.Replace("-", "");
        txtPhoneOther.Text.Replace("_", "");

        location.ContactWork = txtPhoneWork.Text.Trim();
        location.ContactMobile = txtMobile.Text.Trim();
        location.ContactOther = txtPhoneOther.Text.Trim();
Run Code Online (Sandbox Code Playgroud)

但它不更换和是否有任何这样既方法-_可在单一的功能来代替.

Nic*_*ver 15

.Replace() 返回执行替换的字符串(它不会更改原始字符串,它们是不可变的),因此您需要这样的格式:

txtPhoneWork.Text = txtPhoneWork.Text.Replace("-","");
Run Code Online (Sandbox Code Playgroud)