-
"Invisible" & sign.
I can't cut/paste because the machine with the IDE is not connected to the net!
I place a label on the screen, and a button. When the button is pressed, it does:
label1.Text = ">>>&<<<";
What shows up on the screen is >>><<<. If I take the length of the .Text field it shows 7. If I write >>>&&<<< it appears right, (ie. a single ampersand), on the screen, but the length is now 8.
Whats wrong here?
-
Use a verbatim string literal.
Code:
label1.Text = @">>>&<<<";
-
The &-char is used to indicate that the following char is used for keyboard shortcuts.
"&Next" would spell "Next", once you press Alt, it would be "Next" and pressing "N" on the keyboard would select this action.
-
Still not present on the screen using the @ operator. It is in a string for example.
-
I wasn't thinking and nvoigt set me straight.
It wouldn't work. The problem is as nvoigt puts it. For the & sign to stop being treated as a special character, set the UseMnemonic property to false.
Code:
label1.UseMenmonic = false;
label1.Text = ">>>&<<<";
There's no need for a verbatim string either.
-
Yeah, that works. That's pretty gross isn't it.
-
Not really. The API is free to establish the rules of how it operates. Since Mnemonics is such a fundamental aspect of a Windows GUI, it's perfectly acceptable. What would be gross was for the API to not give you the option to disable mnemonics on a control basis.
-
I don't want to get drawn into a debate here. I will say that I have googled, and searched the online documentation here for a couple of days and the solution was not apparent. The product is being pushed as a beginner tool, and beginners are not good at searching for stuff like this. The product is also making great pains to show it's xml features, where the & symbol is frequently used, (indeed, how I came upon the problem), yet I cannot find it there either.
We disagree, fair enough.
-
Yes, we disagree. Although I'm not sure what product you are talking about.
-
MS Visual Studio 2008, Professional. C# more generally.
-
Hmm... I don't know who told you this was for beginners. It's a programming language. Part of the apprenticeship process is exactly hunting down for answers to things we don't know. As we gather knowledge things start to fit in place and all will appear more easy and make more sense. It's not the other way around. In the beginning everything will appear confusing and difficult.
That's what being a beginner is all about. Confused, bewildered and sometimes slightly annoyed.
-
Microsoft have been presenting C# as the way forward to get many new people into development. If you browse the marketting bumph, (:rolleyes:), it is full of stuff like that.
The fact that I could not find it, (I have been a professional software engineer, i.e. in an office being paid for it, for 30+ years), indicates to me that it is not immediately apparent.
-
The & greatly predates C# for its use in mnemonics; it was part of the original WinAPI, and everything that's built upon the WinAPI, including Windows Forms, still recognizes it.
-
Use ">>>&&<<<"
(double &)
-
It may be a problematic solution if, as implied, you later need to read the string length, magos.