-
September 28th, 2016, 08:53 PM
#1
How to replace characters in a mixed string?
Hi guys! Can anyone please tell me why the code below is not working? Thanks!
private void tipoComboBox_SelectedValueChanged(object sender, EventArgs e)
{
if (tipoComboBox.SelectedIndex == 0)
{
string Str = valorTextBox.Text;
Str = Regex.Replace(Str, @"-", "");
valorTextBox.ForeColor = Color.Blue;
valorTextBox.Text = Str;
}
if (tipoComboBox.SelectedIndex == 1)
{
string Str = valorTextBox.Text;
Regex.Replace(Str, "R$", "-R$");
valorTextBox.ForeColor = Color.Red;
valorTextBox.Text = Str;
}
}
-
September 29th, 2016, 04:55 PM
#2
Re: How to replace characters in a mixed string?
You should put a breakpoint on the first if statement in the code and debug it.
At any rate, why are you using Regex replace when String has it's own Replace method?
-
October 2nd, 2016, 07:53 PM
#3
Re: How to replace characters in a mixed string?
Code:
private void tipoComboBox_SelectedValueChanged(object sender, EventArgs e)
{
if (tipoComboBox.SelectedIndex == 0)
{
string Str = valorTextBox.Text.Replace("-", "");
valorTextBox.ForeColor = Color.Blue;
valorTextBox.Text = Str;
}
if (tipoComboBox.SelectedIndex == 1)
{
string Str = valorTextBox.Text.Replace(R$", "-R$");
valorTextBox.ForeColor = Color.Red;
valorTextBox.Text = Str;
}
}
Try this.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|