my code -
txtPhoneWork.Text.Replace("-","");
txtPhoneWork.Text.Replace("_", "");
txtMobile.Text.Replace("-", "");
txtMobile.Text.Replace("_", "");
txtPhoneOther.Text.Replace("-", "");
txtPhoneOther.Text.Replace("_", "");
loca开发者_运维百科tion.ContactWork = txtPhoneWork.Text.Trim();
location.ContactMobile = txtMobile.Text.Trim();
location.ContactOther = txtPhoneOther.Text.Trim();
but it is not replacing and is there any method so that both -
and _
can be replaced in single function.
.Replace()
returns the string with the replacement performed (it doesn't change the original string, they're immutable), so you need a format like this:
txtPhoneWork.Text = txtPhoneWork.Text.Replace("-","");
get the replaced string in some variable
you can try this to replace multiple characters in single function string value= System.Text.RegularExpressions.Regex.replace(value, @"[-_]", "");
精彩评论