views:

142

answers:

2

my code -

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();

but it is not replacing and is there any method so that both - and _ can be replaced in single function.

+6  A: 

.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("-","");
Nick Craver
there would be a space in "", Replace("-"," "); OR Replace("-","");
ppp
A: 

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, @"[-_]", "");

Bala