I am developing a piece of software in C #, and the end result is an Excel spreadsheet. A spreadsheet header is created using several variables to accurately explain what a spreadsheet is. One of the variables is a string that contains such data:
'1.1.1'
I need to convert it at the time of creating the table:
'1_1_1
I tried to use the method String.Replace, but it just ignores it. Any ideas?
String.Replace
Regards
I bet you do this:
myString.Replace(".","_");
When you should do this:
myString = myString.Replace(".","_");
Remember that .Net strings are immutable, so any changes result in a new string.
, string.Replace. :
string.Replace
text = text.Replace('.', '_');
Replace - . .NET - .
Replace
string.Replace, , ?
yourString.Replace(".", "_");
.
string newString = yourString.Replace(".", "_");
, , String.Replace. , String.Replace , .
string foo = "1.1.1"; foo = foo.Replace('.', '_');
String input = "1.1.1"; input = input.Replace(".", "_");
, , :
string myString = "1.1.1"; myString = myString.Replace('.', '_');
String.Replace - :
private void button1_Click(object sender, RoutedEventArgs e) { String myNumbers = "1.1.1"; Console.WriteLine("after replace: " + myNumbers); myNumbers = myNumbers.Replace(".", "_"); Console.WriteLine("after replace: " + myNumbers); }
:
after replace: 1.1.1 after replace: 1_1_1