473,406 Members | 2,956 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

how to print string esc characters

Hi

im sending this string to a device
String cmd = ""N1\x0D")

this device needs the esc \x0D on the end where you see it

After i have sent this string i want to print it our to a rich
textbox, but the \x0D keeps performaing the CR
I dont want the CR to occur, i want the string to print the actual
\x0D letters.

How can i do this after i have sent the string as is to the device.
How to i convert it so the esc characters print ?
thanks for any help

Peted
May 15 '07 #1
2 3722
Peted,

You are going to have to look for the character code in the string and
then replace it with the literal "\x0D". Just call the replace function,
looking for a string with that value, and then replace it with the actual
string @"\x0D" (or \\x0D).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Peted" wrote in message news:q0********************************@4ax.com...
Hi

im sending this string to a device
String cmd = ""N1\x0D")

this device needs the esc \x0D on the end where you see it

After i have sent this string i want to print it our to a rich
textbox, but the \x0D keeps performaing the CR
I dont want the CR to occur, i want the string to print the actual
\x0D letters.

How can i do this after i have sent the string as is to the device.
How to i convert it so the esc characters print ?
thanks for any help

Peted
May 15 '07 #2

<Petedwrote in message news:q0********************************@4ax.com...
Hi

im sending this string to a device
String cmd = ""N1\x0D")

this device needs the esc \x0D on the end where you see it

After i have sent this string i want to print it our to a rich
textbox, but the \x0D keeps performaing the CR
I dont want the CR to occur, i want the string to print the actual
\x0D letters.

How can i do this after i have sent the string as is to the device.
How to i convert it so the esc characters print ?
Here's my version which I use for generating C# code (note not all cases are
tested), your string would become "\"N1\r". It should be easy enough to
remove the switch statement if you always want the hex code:

public static string EscapeLiteralString(string literal)
{
StringBuilder sb = new StringBuilder("\"", literal.Length + 2);
for (int index = 0; index < literal.Length; index++)
{
Char c = literal[index];
if (c < 32)
{
sb.Append('\\');
switch (c)
{
case '\0':
sb.Append('0');
break;
case '\a':
sb.Append('a');
break;
case '\b':
sb.Append('b');
break;
case '\f':
sb.Append('f');
break;
case '\n':
sb.Append('n');
break;
case '\r':
sb.Append('r');
break;
case '\t':
sb.Append('t');
break;
case '\v':
sb.Append('v');
break;
default:
sb.Append("x").Append(((UInt16)c).ToString("X02")) ;
break;
}
}
else if (c < 127)
{
if (c == '\"' || c == '\"' || c == '\\')
sb.Append('\\');
sb.Append(c);
}
else
{
int utf32 = Char.ConvertToUtf32(literal, index);
if (utf32 < 0x10000)
sb.Append("\\u").Append(utf32.ToString("X04"));
else
sb.Append("\\U").Append(utf32.ToString("X08"));
if (utf32 != c)
index++;
}
}
return sb.Append('\"').ToString();
}

>

thanks for any help

Peted

May 15 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Olaf \El Blanco\ | last post by:
typedef struct { unsigned char data; } packet; typedef struct { packet info; int nro_reg; } Buffer_Network; void test(void) { FILE *filename;
15
by: wizardyhnr | last post by:
i want to try ANSI C99's unicode fuctions. so i write a test program. the function is simple, but i cannot compile it with dev c++ 4.9.9.2 under windows xp sp2, since the compiler always think that...
1
by: iwongu | last post by:
Hi, I have a question about std::wcout and its underlying C functions. According to C99, a stream have an orientation type that is one of byte-oriented or wide-one, and it is determined by the...
2
by: Phoe6 | last post by:
print and softspace in python In python, whenever you use >>>print statement it will append a newline by default. If you don't want newline to be appended, you got use a comma at the end (>>>print...
6
by: Greg Esres | last post by:
I have some text lines to print that are much longer than the width of the paper, maybe as much as 6 times. For a given page, I'd like everything that doesn't fit to print on a second page, and...
8
by: =?gb2312?B?yMvR1MLkyNXKx8zs0cSjrM37vKvM7NHEsru8+7z | last post by:
I lookup the utf-8 form of delta from the link. http://www.fileformat.info/info/unicode/char/0394/index.htm and then I want to print it in the python ( I work under windows) #!/usr/bin/python...
13
by: ramif | last post by:
Is there a way to print extended ASCII in C?? I tried to code something, but it only displays strange symbols. here is my code: main() { char chr = 177; //stores the extended ASCII...
38
by: ssecorp | last post by:
char* reverse(char* str) { int length = strlen(str); char* acc; int i; for (i=0; i<=length-1; i++){ acc = str; } return acc; }
2
by: Flying Kite | last post by:
Hi All, I want to know how to print chinese characters on Zebra Printer, following code working fine with English string, but it's not working for Chinese string. It shows ASCII characters instead...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.