I'm trying to set an error message which contains an ampersand via an ErrorProvider.
First attempt went like this :
errorProvider.SetError(someControl, "You have not accepted the Terms & Conditions");
This does not display the ampersand character. Googling suggested the following :
errorProvider.SetError(someControl, "You have not accepted the Terms &&& Conditions");
It works (i.e. displays one ampersand), but I would like to understand why it works. Any ideas ?
EDIT : for the System.Windows.Forms.Label control, there is a property called : UseMnemonic which can be set to False. Does ErrorProvider have anything like this ?
“&” is a special character in forms that is meant to underline the following character. So if you use it like:
myButton.Text = "&Close";
it will underline the 'C' character which will also become a hotkey. If you don't want that to happen, you use double ampersand like '&&' in your text.
Related
In my windows phone project, I would like the user to enter his phone number in xxx-xxx-xxxx format. The country code it not required. I tried to implement regex, but i am not getting it right. I just want it to be displayed to the user as he enters it, nothing more, nothing less. This is what I have used
^\(\d{3}\) ?\d{3}( |-)?\d{4}$
But no matter what i put in, I always get this error (in this case 5) "Unrecognized escape sequence". I noticed, this is only with reference to the oblique. When I add a "" after it, the error goes away, but I do not get what I want. Is there a special way to input numbers in the textbox in than manner, on the XAML level?
Thanks in advance!
Put your regex inside verbatim string and also put the space, hyphen inside a group and make it as optional.
#"^\(\d{3}\)([- ]?)\d{3}\1\d{4}$"
DEMO
For testing your RegEx you can use this site: http://www.regexlib.com/RETester.aspx?AspxAutoDetectCookieSupport=1.
For your xxx-xxx-xxxx format I would use it:^\d{3}-?\d{3}-?\d{4}$
The following console app works fine:
class Program
{
static void Main(string[] args)
{
string plainx = "‘test data’ random suffix";
plainx = Regex.Replace(plainx, #"‘", string.Empty);
Console.WriteLine(plainx);
}
}
However its giving me trouble in an ASP.Net application.. I am attaching a screenshot of the VS Debug watch window and Immediate window
(Click for larger view)
As you can see, the Regex.Replace in the Immediate Window works - but somehow it is not working in the code (line 71). I've also used String.Replace without success.
Edit
It seems the value that was stored in the DB is something than what the editor shows... kind of weird..
Have you actually examined the text being compared? What Unicode code points does it contain?
Your code shows you trying to replace the glyph '‘', which is a left "smart quote". The character's name is LEFT SINGLE QUOTATION MARK and its code point is 0x2018 (aka '\u2018'). This is a character you can't ordinarily enter on a keyboard.
What you are probably seeing is the glyph '`', a "backtick". Its character name is GRAVE ACCENT and its code point is 0x0060 (aka '\u0060'). This is the character typed when you press the [unshifted] tilde key on a standard US keyboard (leftmost key on the number row).
It might, of course, be any of a number of other characters whose glyph is similar to a single quote. See Commonly Confused Characters for more information.
The single quote in your code is not the same single quote in the string you are testing.
Use the hex value returned from testx[0] directly to guarantee that we are using the correct quote.
plainx = Regex.Replace(plainx, "\u2018", string.Empty);
try to replace :
#"‘" to #"\‘"
code :
string plainx = "‘test data’ random suffix";
plainx = System.Text.RegularExpressions.Regex.Replace(plainx, #"\‘", string.Empty);
Console.WriteLine(plainx);
Console.Read();
I have the following code :
Process.Start("cmd.exe");
System.Threading.Thread.Sleep(1000);
SendKeys.Send("{D}{I}{R}{SPACE}{ENTER}");
I know that Space does not do anything here, but I'm trying to solve another issue so my question is why do I get this exception Keyword "SPACE" is not valid.? How can I send space?
You only need to escape special characters (list at the page here), the rest, including space, can just be written as is;
SendKeys.Send("DIR {ENTER}");
How would one enter special characters into a Label in C# (Windows Forms)?
If you try to write a "&" into a label you'll get a sort of underscore instead..
So what's the C# equivalent of "&"? ("\&" obviously doesn't work).
Two ways:
Escape it with another ampersand (&&).
Set UseMnemonic for that label to false. This causes all ampersands within the text to be taken literally so you don't need to double any of them. You'll lose the underlining and access key features though.
You can set the value either in the designer, or in code:
myLabel.UseMnemonic = false;
myLabel.Text = "Text&Text";
Add another ampersand in front of it, so: &&
Or have a look at the following: Label.UseMnemonic (MSDN documentation)
You can escape & by adding it two times, to try &&.
I don't know how to use '&' in the designer, but in the code you can use '&&' for showing one '&'
Try this:
((char)0x26).ToString()
I'm facing a simple problem that bugs me...
I have a MaskedTextBox and I want the user to be able to enter 3 numbers at the end :
"My Masked Text Box : XXX"
This text will be translated. The problem is, this control uses Microsoft's recipe to validate the input and in this example, the final display will look like this :
"My M_sked Text Box : _"
The letter 'a' is considered like a control caracter instead of a simple text caracter. I can backslash it but when the text is translated I have to do it again and I think it's ridiculous to have to do something like that...
I hope I'm being clear...
Thanks in advance for your help !
The 'a' needs to be quoted as a literal. The Mask should be something like:
My M\asked Text Box : 000
You should use '9' rather than '0' as the placeholder for an optional numerical character.
Of course any other of the characters that match mask options should be 'literal' too.
http://msdn.microsoft.com/en-us/library/system.windows.forms.maskedtextbox.mask.aspx
After reading the comments I'd like to add another suggestion (you clearly understood about literals -- the problem is your translation.)
Would it be feasible to run the translated text strings through a filter that put literal-quotes in where possible? It's not that nice a solution, because if Microsoft added new control characters it'll break your filter, but I think it would work.