single byte characters ? how many bytes for 37 characters ? - bitshift

05-Jul-07 11:43:07
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 ?
reply
 
 

single byte characters ? how many bytes for 37 characters ? - Nicholas Paldino [.NET/C# MVP]

05-Jul-07 12:39:08
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]
- mvp@spam.guard.caspershouse.com
reply
 

single byte characters ? how many bytes for 37 characters ? - Peter Duniho

05-Jul-07 01:28:20
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
reply
 

single byte characters ? how many bytes for 37 characters ? - Ignacio Machin \( .NET/ C# MVP \)

05-Jul-07 02:42:19
Hi,


I addition to the other posts, post here your field definition and the code
you are using.
reply
 

single byte characters ? how many bytes for 37 characters ? - bitshift

05-Jul-07 04:22:38
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.
reply
 
Use [,][] as parameter
promotion
Silverlight    WPF    WCF    WWF    LINQ   
JavaScript    AJAX    ASP.NET    XAML   
C#    VB.NET    VB 6.0    GDI+    IIS    XML   
.NET Generics    Anonymous Methods    Delegate   
Visual Studio .NET    Expression Blend    Virus   
Windows Vista    Windows XP    Windows Update   
Windows 2003 Server    Windows 2008 Server   
SQL Server    Microsoft Excel    Microsoft Word   
SharePoint    BizTalk    Virtual Earth   
.NET Compact Framework    Web Service   

"Everything" RSS / ATOM Feed Parser
How to send and receive messages through message queuing in .Net
How to Read text file as database
SQL Server 2005 Paging Performance Tip
Display code of web page.
Fully Scalable Excel File Importer class for .net using Microsoft Jet driver
Generic Chart Color Manager class that can be used for any charts
Helper class to style the infragistics wingrid
Using Reflection to detemine as Assembly Info in and out.
Helper class to play with Window (Owners and position)
Resolving displayname from the culture using the XmlLanguage and LanguageSpecificStringDictionary class