Reputation: 13
Trying to remove a Dot from a String i´m experiencing a problem. With different Chars such as "," or "-" its working properly but the Dot won´t disappear.
Got a TextBox with the Name nr_tb. I Input Hello.World and my MessageBox outputs the same. Changing the Dot in the Replace function with a "," works.
Not working:
string line;
private void nr_tb_TextChanged(object sender, TextChangedEventArgs e)
{
line = nr_tb.Text.Replace(".","");
MessageBox.Show(line);
}
Working:
string line;
private void nr_tb_TextChanged(object sender, TextChangedEventArgs e)
{
line = nr_tb.Text.Replace(",","");
MessageBox.Show(line);
}
Upvotes: 0
Views: 1089
Reputation: 60
string number= "2.36";
string newNumber = number.Replace(".", "");
Upvotes: 1
Reputation: 151
It might be another character that seems like a DOT. Char code of DOT is 46
so if you get this char code in your string you can easily Replace(".", "");
it.
This method show each char code of a string:
private static string DotRemover(string temp)
{
string _Result = string.Empty;
foreach (byte a in Encoding.UTF8.GetBytes(temp.ToCharArray()))
{
_Result += a.ToString() + Environment.NewLine;
}
return _Result;
}
OR
you can replace everything that look likes a DOT :
public static string CleanNumb(string numb)
{
foreach (char c in ".,'´")
numb = numb.Replace(c, ' ');
return numb.Replace(" ", "");
}
Upvotes: 0