I'm try to replace "." to "_" in a string... i use Regex.Replace()... so my code is Regex.Replace("abc.123", ".", "_") but it return _______ to be...so can anyone help on this??
Printable View
I'm try to replace "." to "_" in a string... i use Regex.Replace()... so my code is Regex.Replace("abc.123", ".", "_") but it return _______ to be...so can anyone help on this??
Or do you really want to use regex?Code:string myString = "This is a sentence.";
myString.Replace('.', '_');
any other function able to provide this?Quote:
Originally Posted by Tischnoetentoet
What's wrong with using String.Replace( )?Quote:
Originally Posted by lsy
For something so basic, you'd be mad not to use string.Replace().
Use stringVariable.Replace(".", "_") since you don't seem to know what a regular expression is. stringVariable.Replace(".", "_") will return a new string with "." replaced with "_" in stringVariable, just like you wanted.
With regular expressions, "." means "any character except newline and carriage return". That's why you only get underscores. Regular expressions support escaping, so preceed the dot with a backslash to bypass its special meaning. Since C# also uses backslashes for escaping, you need to escape the backslash as well: "\\."
Thanks for your explanation...Quote:
Originally Posted by andreasblixt