0

This is what i have under button 1.. I am entirely new to this program. am I missing something? there is no errors but button does no fill its purpose and doesn't change "A" to asterisk aka *. I eventually want to replace all capital letters in a word with *, but for now I just want to learn how to do the letter "A".

string orgstring = textBox1.Text;
string Asteriskstring = textBox1.Text.Replace("A","//*");

3 Answers 3

4

You're doing it, although I don't know what the forward slashes are for, and orgstring is redundant in this example; the result is held by Asteriskstring, so assuming you want to display that value you will need to update the UI:

textBox1.Text = Asteriskstring;
1
  • well thanks! It works now... is there anyway i can make this work for all capital letters and not just the capital letter A? or would i have to use something other than Replace? Feb 5, 2013 at 20:33
1
string sSource = "AcccADFGHcsdD";
string sDest = Regex.Replace(sSource, @"[A-Z]", "*");

will return:

"*ccc*****csd*"

In your case:

string orgstring = textBox1.Text;
string Asteriskstring = Regex.Replace(orgstring, @"[A-Z]", "*");
0
0

Are you trying to change the contents of the textbox? If so...

        string textBox1.Text = textBox1.Text.Replace("A","//*");



Edit: The best way would probably be to combine Arie's answer and my original answer. You want to use their regular expression replacement to change the textbox's text; the text is both your source AND destination, so:

textBox1.Text = Regex.Replace(textBox1.Text, "[A-Z]", "*");

If this doesn't work, the namespace containing the Regex class might not be included in your program. The Regex class is located in the System.Text.RegularExpressions namespace. To enable use of the Regex class, add the code below to the part of your code containing all the statements starting with using:

using System.Text.RegularExpressions;
1
  • yes i am. but I eventually want to Change From not just using A but A-Z how can that be done? Feb 5, 2013 at 20:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.