4

If I build a simple string like this:

string myStr = "Kayla & William";

And then simply set the label text on a form like this:

lbl_Phrase.Text = myStr;

The output in the form removes the ampersand (&)

enter image description here


I've tried:

  • escaping the &
  • ASCII encoding
  • char.ConvertFromUtf32(38)

When I debug and step through the code the string includes the & just fine. Also, I can write the string to Debug.WriteLine(myStr); and it looks great.

Is the problem related to how the form displays the string? How can I get the label to display the &?

Automate This
  • 30,726
  • 11
  • 60
  • 82

1 Answers1

7

you need to escape it with use double ampersand && for displaying single ampersand &

Note : single & has different meaning that it will be treated as ACCESS KEY PREFIX character and you need to escape it with another &

Try This :

&&

OR

you can set UseMnemonic property of the label to false, and give only one ampersand & .when you set UseMnemonic to false ampersand will be treated as normal literal and displayed.

Sudhakar Tillapudi
  • 25,935
  • 5
  • 37
  • 67