473,406 Members | 2,619 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.

StringBuilder question : Adding ASCII control schars ?

Hi

I am construncting a string containing some control chars (STX/ETX)

I noticed that adding a byte with value 2 is the same as adding a character
'2' ???

How can i solve this problem ?
Is the stringbuilder restricted to pure readable ascii code contents ?
sb.Append(2); // ascii code 2
sb.Append('2'); // ascii char '2'

Johan
Nov 16 '05 #1
1 6148
In the case of sb.Append(2), the compiler is picking the overload

StringBuilder Append (int value);

If you want the "2" to be treated as the ASCII value of the character, you
want it to pick the overload

StringBuilder Append (char value);

Try this:

sb.Append ((char) 2);

-vJ

"Sagaert Johan" <RE*************@hotmail.com> wrote in message
news:uK**************@TK2MSFTNGP12.phx.gbl...
Hi

I am construncting a string containing some control chars (STX/ETX)

I noticed that adding a byte with value 2 is the same as adding a
character
'2' ???

How can i solve this problem ?
Is the stringbuilder restricted to pure readable ascii code contents ?
sb.Append(2); // ascii code 2
sb.Append('2'); // ascii char '2'

Johan

Nov 16 '05 #2

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

Similar topics

37
by: Kevin C | last post by:
Quick Question: StringBuilder is obviously more efficient dealing with string concatenations than the old '+=' method... however, in dealing with relatively large string concatenations (ie,...
6
by: W1ld0ne74 | last post by:
The code below was coded to to take the xml that is sent to and from a Data Object in our system and strip out any strange characters that may creap into the xml that is received from a Mainframe...
20
by: Alvin Bruney | last post by:
On the advice of a user, I've timed stringbuilder v string. Here are the results. Here are the numbers: Total # queries 3747 Time in Milliseconds StringBuilder: String...
12
by: | last post by:
I know how to use a StringBuilder, which supposedly does not create a new copy of it each time you modify it contents by adding or removing text. But, I wonder how does it do that internally ? I...
5
by: Andrea | last post by:
Hy I have a litle problem : I have to invoke a function in an unmanaged dll (writen in C) from C# ------------------------------------------------ int string_modify(unsigned char*...
7
by: Mike P | last post by:
I read somewhere that if you are concatenating more than 2 or 3 strings you should use StringBuilder as it will use up less resources. Does this apply when you are building up a string (for...
2
by: Mad Scientist Jr | last post by:
I seem to have more data in my stringbuilder than .ToString is returning. Any idea why? Is there a limitation? Workaround? Thanks ?Stringbuilder1.Length 145264...
7
by: rhkodiak | last post by:
I was in an interview question what is the most efficient way to sort a string for example "010101", the result would then be "000111", and write the code on how to do this. I wrote the code for...
34
by: raylopez99 | last post by:
StringBuilder better and faster than string for adding many strings. Look at the below. It's amazing how much faster StringBuilder is than string. The last loop below is telling: for adding...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.