|
\unnnn doesn't work any particular way, it's just a string..
Of course it works that way in Java and C# and no doubt some other places as well, but there's no guarantee that it always does and OP should have specified it
|
|
|
|
|
Well, this is the C# forum...
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
Why does that matter? It's not about the string "\Uanything" (ie a string containing the actual character), but about a string containing "\\Uanything" that has to be converted the the first form. Anything could still be in any form - nowhere did he say that it originates from C# sourcecode.
|
|
|
|
|
I didn't have a problem understanding what OP wanted to do. Luc didn't have a problem. Richard didn't have a problem. jschell didn't have a problem. OP didn't have a problem understanding Luc's answers.
I'm not going on a troll-feeding expedition. End of discussion.
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
Actually they all had problems understanding what he meant.
Luc's first answer doesn't answer the question, Richard's answer doesn't the question, Luc's first version of his second answer parsed it as decimal aswell IIRC and jschell just noted a problem with what the OP is trying to do.
Peter_in_2780 wrote: I'm not going on a troll-feeding expedition. End of discussion.
F*** you.
It was a legitimate discussion.
You are the troll here, not me.
modified on Thursday, May 12, 2011 3:42 AM
|
|
|
|
|
David1987 wrote: Richard's answer doesn't the question
Precisely, because I did not think the question was clear, and it had already received enough suggestions from other people. BTW I was not confused about the hex/decimal question; as you rightly pointed out the OP did not specify what the number format was.
The best things in life are not things.
|
|
|
|
|
David1987 wrote: Luc's first version of his second answer parsed it as decimal aswell IIRC
Wrong.
I edited to improve the error checking, basically I added s==null || s.Length!=6 || s[0]!='\\' || s[1]!='U' to the if(...) throw statement.
Now stop this silly dispute, none of us know exactly what the OP intended, as is often the case, unfortunately. That is why I ended up providing two different answers, assuming one of them would hit the actual question.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
And let me remind you, you are wrong.
The OP did not specify that the number had to be in HEX, therefore it was not clear.
|
|
|
|
|
Who the f*** upvoted this?
|
|
|
|
|
Correcting Univotes now. Luckily my jedi powers are OK, so you'll gain more then you lost
|
|
|
|
|
Now look[^] what you've done.
The best things in life are not things.
|
|
|
|
|
"/U0061" gives the string /U0061; I think you mean "\U0061".
The best things in life are not things.
|
|
|
|
|
yea, sorry about that mistake.
|
|
|
|
|
if what you have is a six-character string containing a real backslash, a U, and four hex digits, then you could turn that into a single character like so, however this situation is rare, it would typically occur only if you plan on writing your own C# compiler!
string s=@"\U0061";
int uni;
if (s==null || s.Length!=6 || s[0]!='\\' || s[1]!='U' ||
!int.TryParse(s.Substring(2, 4), NumberStyles.HexNumber, null, out uni))
throw new Exception("Bad unicode string in: "+s);
char c=(char)uni;
log("uni="+uni.ToString("X4"));
log("c="+c);
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
modified on Wednesday, May 11, 2011 1:23 PM
|
|
|
|
|
Is there a real problem here?
As noted you have a simple character one which will be in string if the string is created correctly.
However you CANNOT use a single C# data type 'char', to represent the entire supported character set range.
So if that is your goal you will fail.
Read up on "surrogate pairs" to find out why.
|
|
|
|
|
Hi experts,
I'm creating a custom control DerivedPanel . It's derived from System.Windows.Forms.Panel . There are no other controls on DerivedPanel . Instead it draws custom items called Devices .
I'd like to resemble the selection behaviour of Windows XP's desktop. That includes holding the CTRL button down while dragging a selection rectangle. That should cause each Device within the rectangle to toggle its selection state.
For the CTRL key, I used
protected override void OnKeyDown(KeyEventArgs e)
{
Console.WriteLine("OnKeyDown: " + e.KeyValue.ToString());
base.OnKeyDown(e);
if (e.Control)
{
Console.WriteLine("Setting XOR devices...");
_selectionXoringDevices.AddRange(_project.Devices.SelectedDevices);
}
else
Console.WriteLine("Lazying...");
}
Now the problem is that as long as I'm holding down the CTRL key, this event keeps firing over and over again.
I need it to fire once on keypress.
Funny enough, the corresponding OnKeyUp() works just that way.
How can I get a method to execute once on pressing down the CTRL key?
Edit: I need this to work in .NET 2.0.
Ciao,
luker
modified on Thursday, May 12, 2011 2:06 AM
|
|
|
|
|
You might put your current handler code inside a test:
if (!KeyEventArgs.IsRepeat) {
}
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Thank you Luc,
this seems to be exactly like what I'm looking for. Unfortunately, I'm bound to .NET 2.0 and forgot to mention that in my original question, which I edited.
Can you think of another way of getting exactly one keypress?
Ciao,
luker
|
|
|
|
|
you can construct IsRepeat yourself by remembering the last key down (both KeyValue and Time), then compare the old ones with the new ones; when the TimeSpan is less than some value (maybe set to SystemInformation.KeyboardDelay) it is likely to be an auto-repeat.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
I kind of worked around it by using a boolean to remember whether CTRL is pressed or not.
Ciao,
luker
|
|
|
|
|
This would have been my solution.
|
|
|
|
|
Hi
I need some help regarding Regex as my knowledge of it is rather poor. I have a string like the following:
"John Doe, john@bleh.com, (H) 0412623423234, (W) 1290034589345, Jane Doe, jane@bleh.com, (H) 041235423234, (W) 1290034589345"
What I need to do is to retrieve each Email address as well as each Home and Work number separately. After retrieving the separate values I would then like to store the related ones together as one comma-separated property like in the following example:
customer.Email = "john@bleh.com,jane@bleh.com";<br />
customer.HomePhone = "0412623423234,041235423234";
I already used a Regex pattern to retrieve all the email addresses in the string, but it seems to be a bit more tricky with the different phone numbers. Any advice/help?
|
|
|
|
|
You may find this solution just made for you Helpful.
string Text = "John Doe, john@bleh.com, (H) 0412623423234, (W) 1290034589345, Jane Doe, ";
Regex HomePhoneRegex = new Regex(@"\(H\)[ ]*\d{13}");
Regex WorkPhoneRegex = new Regex(@"\(W\)[ ]*\d{13}");
Regex EmailRegex = new Regex(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
String HomePhone = String.Empty;
String WorkPhone = String.Empty;
String Email = String.Empty;
if (HomePhoneRegex.Matches(Text).Count == 1)
{
HomePhone = HomePhoneRegex.Matches(Text)[0].Value.Replace("(H)", String.Empty).Trim();
}
if (WorkPhoneRegex.Matches(Text).Count == 1)
{
WorkPhone = WorkPhoneRegex.Matches(Text)[0].Value.Replace("(W)", String.Empty).Trim();
}
if (EmailRegex.Matches(Text).Count == 1)
{
Email = EmailRegex.Matches(Text)[0].ToString();
}
Regards,
Hiren.
-"I don't know, I don't care, and it doesn't make any difference".
|
|
|
|
|
Thanks that did help
|
|
|
|
|
You're welcome.
Glad it helped you.
Regards,
Hiren.
-"I don't know, I don't care, and it doesn't make any difference".
|
|
|
|