Peted wrote:
> Hi thanks,
>
> ive just realised the problem seems to be my doing, but i dont know
> how to fix it
>
> ive found out that this sequence
>
> EG: "W01RS|\x4E\x31\x0D" (this sends the characters N1<CR>) to the
> ip device serial port 1
>
> the above works(ie it does what i want) if i use it as a string
> variable and send it that way
>
> ie String cmd = "W01RS|\x4E\x31\x0D";
>
> but if i enter W01RS|\x4E\x31\x0D into a textbox, then send the
> Textbox.text value the esc \x stuff does not work. All the \x get
> sent as litteral characters without performing the esc functions.
>
> Can anyone tell me how i can make it process the esc after eneter into
> textbox, and getting the text value. I need to do this as a testing
> application, so a user can manually enter different commands to test
> them out
>
> thanks for any help
>
> Peted
>
Use a regular expression to match the escape sequences and use a
delegate in a replace to parse them and convert them into characters.
Example:
string s = Regex.Replace(@"W01RS|\x4E\x31\x0D", @"\\x[\dA-F][\dA-F]",
delegate(Match m) { return
((char)int.Parse(m.Groups[0].Value.Substring(2),
NumberStyles.HexNumber)).ToString(); });
--
Göran Andersson
_____
http://www.guffa.com