473,805 Members | 2,001 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

single byte characters ? how many bytes for 37 characters ?

Im pulling a string out of a text field in sql and into a byte array in my
C# code. Help frefresh my memory here, a single asci character is 1 byte
correct ? So why is a string that is 37 characters long, result in a byte
array that is 2224 elements in length ?
Jul 5 '07 #1
4 5217
bitshift,

I don't know of any encoding that is going to produce those numbers of
bytes when converting.

Is the field in SQL Server a text field, or is it a char/varchar field?
If it is a text field, then you probably shouldn't have this problem.

My guess is that this is a char field which has a fixed length of 2224,
and that is why the string is that long. If you want the field in the
database to not have a fixed length, then the column has to be a varchar
field.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"bitshift" <jo***@aol.comw rote in message
news:ex******** ******@TK2MSFTN GP05.phx.gbl...
Im pulling a string out of a text field in sql and into a byte array in my
C# code. Help frefresh my memory here, a single asci character is 1 byte
correct ? So why is a string that is 37 characters long, result in a byte
array that is 2224 elements in length ?

Jul 5 '07 #2
On Thu, 05 Jul 2007 08:43:07 -0700, bitshift <jo***@aol.comw rote:
Im pulling a string out of a text field in sql and into a byte array in
my
C# code. Help frefresh my memory here, a single asci character is 1 byte
correct ? So why is a string that is 37 characters long, result in a
byte
array that is 2224 elements in length ?
Well, a "char" in C# is a Unicode character, with 2 bytes. That said,
that wouldn't explain a length of 2224 bytes for a 37 character string. I
agree with Nicholas that it's likely what you're getting from the SQL
database isn't really a character string only 37 characters long.

Pete
Jul 5 '07 #3
Hi,

"bitshift" <jo***@aol.comw rote in message
news:ex******** ******@TK2MSFTN GP05.phx.gbl...
Im pulling a string out of a text field in sql and into a byte array in my
C# code. Help frefresh my memory here, a single asci character is 1 byte
correct ? So why is a string that is 37 characters long, result in a byte
array that is 2224 elements in length ?
I addition to the other posts, post here your field definition and the code
you are using.
Jul 5 '07 #4
Yes, the field this string is coming from is a text column. After stepping
through a few more times, I found out I was getting an exception. After
pulling the string from the row, I was trying to decode it from base64, but
if this was an invalid image data, it would bomb. So now im checking the
length of the string first, instead of simply checking my byte array length.
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c omwrote in
message news:ec******** ******@TK2MSFTN GP05.phx.gbl...
bitshift,

I don't know of any encoding that is going to produce those numbers of
bytes when converting.

Is the field in SQL Server a text field, or is it a char/varchar field?
If it is a text field, then you probably shouldn't have this problem.

My guess is that this is a char field which has a fixed length of 2224,
and that is why the string is that long. If you want the field in the
database to not have a fixed length, then the column has to be a varchar
field.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"bitshift" <jo***@aol.comw rote in message
news:ex******** ******@TK2MSFTN GP05.phx.gbl...
>Im pulling a string out of a text field in sql and into a byte array in
my C# code. Help frefresh my memory here, a single asci character is 1
byte correct ? So why is a string that is 37 characters long, result in
a byte array that is 2224 elements in length ?


Jul 5 '07 #5

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

Similar topics

15
16343
by: Reid Nichol | last post by:
Hello, I was wondering if I could control how many bytes are in an int and the byte order. In C/C++ I can use int32 but how do I do this in python? How can I control byte order?
9
2405
by: cylin | last post by:
Dear all, Using sizeof(vector<TYPE>) will always return 16 bytes. If I have N elements ( integer ), the total memory is sizeof(vector<int>)+sizeof(int)*N, or sizeof(vector<int>)*N, or others? Thanks your help.
3
8480
by: mailar | last post by:
HI, Can anyone tell me how is a multi_byte to single byte and vice versa conversion done in DB2. It would be great even if someone can tell me how Oracle does it? Oracle already has functions called to_single_byte and to_multi_byte which convert a given multi byte character to single byte and vice versa respectively. thanks in advance mailar
1
1846
by: Michal Januszczyk | last post by:
I build some web aplication that needs to return some binary data using Response.BinaryWrite(byte data) All is fine, but one thing: the browser does not display "estimated time left" and the size of the binary to be returned. All is right, but the user does not know how big the file will be, nor he nows how long he is going to wait. (All he knows is how many bytes he has downloaded already) What should I do to allow the browser display this...
3
2852
by: Seion | last post by:
Hi, Any body can teach me how to convert double bytes HEX to single byte HEX? I'm not too sure what does this mean. But, it is a requirement from a server software that only allow single byte hex to be transfered to it. Hope can get some help here. Thanks first.
32
6377
by: Guoqi Zheng | last post by:
I am really do not know so much about byte/bit, etc. Question, if I defined a byte(), how can I add a single byte to it? what I want is that I have an array of bytes, I loop that array, look at the value of that individual byte, if that byte is what I want, then I insert it into the new byte(). How can I do it? -- Kind regards
9
4104
by: Morgan Cheng | last post by:
Hi, I once worked for java in embedded system. Since the memory is limited in embedded system, there are some guidelines for programming. One of them is "Don't create too many classes, because each class takes up at least 200 bytes". The 200 bytes are byte-code, not size of a class instance. Since Java and C# is so similar, I am wandering how many bytes will it take for a C# class after compiled into IL code. If it also consumes
1
6132
by: param | last post by:
Hi Everybody, Here i am working on a struts project for japanese. from the front end user may type email id in text box. Here if user enters double byte character mail id, then i have to convert them to single byte character and save it into database. can anyone please reply me with tips, or sample codes.. Thanx in Advance..
5
70962
by: lifehacker | last post by:
Hi, I am a total n00b in C++ and have a basic question: How big is a string: I have discovered the following: bool - 1 byte char - 1 byte int - 2 bytes
3
12485
by: venee | last post by:
Hi, I am working on a application which is developed using java. This application should handle both single byte character sets(English) and Double byte character sets (Japenese - Katakana, kanji, etc.,). And even have to make a conversion between SBCS & DBCS and vice versa too. So if i could get some idea about it and even if some available java code snippet, it will be more helpful.
0
10604
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
10356
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
10361
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
10103
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
9179
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
7644
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
6874
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();...
0
5676
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4316
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

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.