|
prasadbuddhika wrote: i still get the first character in the string
?????????????????????
string s only holds one character. the whole backslash-u-fourdigirs thing is C#'s way to specify a single character by its Unicode character number.
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.
|
|
|
|
|
thanx Luc, i had made a mistake , i had used "U" instead of "u" , when i use "U" it gives me the unrecognized escape sequence . but with "u" it works fine thank you.
|
|
|
|
|
You can parse it as int (the 0061 part) and then cast to char .
|
|
|
|
|
could you please guide me on that. thanx.
|
|
|
|
|
First search for occurrences of \\U[0-9]+ (that's a regex, the backslash is escaped and you may have to doubly-escape it)
Then replace it with (char)int.Parse(match.Value.Split('U')[1]) (though I would refactor that)
|
|
|
|
|
You have a problem. The four digits after the \u are HEX not decimal. So int.Parse won't cut it.
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
OP didn't say so, so how do you know?
|
|
|
|
|
Because that's the way \unnnn works. Big brother to the \xnn convention for single byte characters.
Borrowing a couple of sentences from the Java Language Specification, section 3.2:
A Unicode escape of the form \uxxxx, where xxxx is a hexadecimal value, represents the Unicode character whose encoding is xxxx. This translation step allows any program to be expressed using only ASCII characters.
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
\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.
|
|
|
|