473,883 Members | 1,652 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do you get the number of bytes in a string

Greetings,

What is the C# code that returns the number of bytes in a string such as

323131313531313 33432317E547E31 32357E5553447E4 67E353636303130 303034383532363 2
7E307E56

It should be 80 I think.
thanks
grs
Nov 15 '05
12 21478
damn, you're right.

I meant to type System.Text.Enc oding.Ascii.Get Bytes(value)

I guess you can do
int length = value.Length * 2;
since a char is 2 bytes, and a string stores chars only.

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
test account <bi**********@h ax0r.dyndns.org > wrote:
string value =
"32313131353131 333432317E547E3 132357E5553447E 467E35363630313 030303438353236 3 27E307E56";
byte[] data = System.Text.Enc oding.GetBytes( value);
int length = data.Length;

????


That won't work quite as you've posted it because you need to say
*which* encoding to use - Encoding.GetByt es is an instance method, not
a static method.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #11
test account <bi**********@h ax0r.dyndns.org > wrote:
damn, you're right.

I meant to type System.Text.Enc oding.Ascii.Get Bytes(value)
That still wouldn't work because Ascii should be ASCII, but I get the
idea :)
I guess you can do
int length = value.Length * 2;
since a char is 2 bytes, and a string stores chars only.


But that gets the number of bytes in the internal representation - it
doesn't get the number of bytes written when the data is encoded.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #12

Hi george,

Is your problem resolved?

If you still have anything unclear, please feel free to tell me, I will
help you.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #13

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

Similar topics

2
9710
by: TheKeith | last post by:
can you convert a number into a string by simply adding a set of quotes like this: 5 + "" Thanks
6
3127
by: Nick | last post by:
Hi, How can I check if a number exists by itself in this string by using the RegExp object? --- var mystring = "11,111,01,011"; var match = "1"; var re = new RegExp( match );
1
3922
by: Julie | last post by:
I have the need to preserve the precision of a user-entered number, but that needs to be stored in a (non-string) floating point variable (such as double or decimal). Due to the internal limitations of numerical precision of the double type, I'm presuming that the value will be stored in a decimal for the time being. Supposing the following: decimal d1 = 123.45; decimal d2 = 888.1234567;
1
1888
by: oviam packirisamy | last post by:
how to convert number to string in sqlserver eg:- 10 -> ten display *** Sent via Developersdex http://www.developersdex.com ***
6
22089
by: Andrew Poulos | last post by:
If I have a string with numerals in it and I want to get each number in sequence. Is there a way to do it without parsing the string character by character? For example, str = "abc13def345gh56.7fghdfgf" /* get number(1) returns 13 get number(2) returns 345 get number(3) returns 56.7 get number(4) returns undefined
14
11979
by: ern | last post by:
Does a function exist to convert a 128-bit hex number to a string?
3
7006
by: Todd_Goselin | last post by:
Hello, I've got a problem that I can't fix by myself, I'm fairly new to programming in C and in Unix and so I'm having a tough time doing a simple task of converting a binary number to a string. Can anyone help me with that? Here is the problem: vals2 = ldap_get_values(ld,e,b);
11
1437
by: Mike | last post by:
Why is this converted to a string??? var newidNumber =((idNumber/2).toFixed())+1; Thanks Mike
2
3495
by: ghjk | last post by:
I want to split phone number and string. ex:94778485899 I want to Extract only 778485899 part from the phone number ex: START45.99 Want to remove START from the string and get the floating point number only.Floating point number vary from time to time. May be 23.88, 8.0. This is my code for splitting the floating point number. But it gets only 5 numbers. ex:When i have START888.66 It gets only 888.6.So could some one help me to do the...
0
11109
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10726
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10833
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10405
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9558
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7957
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7114
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4602
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3226
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.