Click here to Skip to main content
15,886,578 members
Home / Discussions / C#
   

C#

 
GeneralRe: Plz help Pin
Not Active27-Feb-08 2:40
mentorNot Active27-Feb-08 2:40 
GeneralRe: Plz help Pin
alok_2k327-Feb-08 3:23
alok_2k327-Feb-08 3:23 
GeneralRepost. Ignore message. Pin
J4amieC27-Feb-08 2:41
J4amieC27-Feb-08 2:41 
GeneralRe: Plz help Pin
Paul Conrad27-Feb-08 3:49
professionalPaul Conrad27-Feb-08 3:49 
GeneralRe: Plz help Pin
Le centriste27-Feb-08 4:24
Le centriste27-Feb-08 4:24 
GeneralRe: Plz help Pin
Paul Conrad27-Feb-08 6:55
professionalPaul Conrad27-Feb-08 6:55 
QuestionhttpWebRequest issue Pin
pelgrim_198327-Feb-08 2:34
pelgrim_198327-Feb-08 2:34 
GeneralByte[], alternate null chars Pin
Malcolm Smart27-Feb-08 2:30
Malcolm Smart27-Feb-08 2:30 
Hi
I am passing data between SQL 2005 and a CLR stored procedure developed in C# via the Service Broker, which uses XML as its transport. It's posted here as the problem is more C# than SQL. The message is read in the C# stored procedure using an SQLDataReader.

The value, a string, is retrieved from the reader as an array of bytes.
//the original string sent was "5129";

byte[] mystring = (byte[])myReader[2];

mystring is populated with the ascii values of each character in my string, but interspersed with nulls ( 0s ), the equivalent of
byte[] mybytes = {53,0,49,0,50,0,57,0};
I can't seem to encode this back to a string. I've tried straight ASCIIEncoding, going via UTF8 (google?) with the following :-
byte[] temp = { 53, 0, 49, 0, 50, 0 , 57 , 0};
byte[] buf = Encoding.Convert(Encoding.GetEncoding("iso-8859-1"), Encoding.UTF8, temp);

//via utf8            
string attempt1 = Encoding.UTF8.GetString(buf, 0, 8);

//straight from byte array
string attempt2 = System.Text.ASCIIEncoding.ASCII.GetString(temp);
//attempt1 & attempt2 both hold  : "5\01\02\09\0"


What am I missing? To cut a long story short I want to convert byte[] temp = { 53, 0, 49, 0, 50, 0 , 57 , 0}; to a string like "5129".

I am currently hacking it with a Replace("\0" , "") which is really professional!

Regards

Knowledge is hereditary, it will find its way up or down. - Luc Pattyn


so you answer don't be scared of failure
The only failure is never to try
Things You've Never Done - Passenger -2008


GeneralRe: Byte[], alternate null chars Pin
Bekjong27-Feb-08 2:55
Bekjong27-Feb-08 2:55 
GeneralRe: Byte[], alternate null chars Pin
Malcolm Smart27-Feb-08 3:01
Malcolm Smart27-Feb-08 3:01 
GeneralRe: Byte[], alternate null chars Pin
Bekjong27-Feb-08 3:14
Bekjong27-Feb-08 3:14 
GeneralRe: Byte[], alternate null chars Pin
Malcolm Smart27-Feb-08 3:37
Malcolm Smart27-Feb-08 3:37 
GeneralRe: Byte[], alternate null chars Pin
Bekjong27-Feb-08 3:47
Bekjong27-Feb-08 3:47 
GeneralAre child threads of an object destroyed when an object is destroyed. Pin
Sunset Towers27-Feb-08 2:26
Sunset Towers27-Feb-08 2:26 
GeneralRe: Are child threads of an object destroyed when an object is destroyed. Pin
Roger Alsing27-Feb-08 2:35
Roger Alsing27-Feb-08 2:35 
GeneralRe: Are child threads of an object destroyed when an object is destroyed. Pin
Not Active27-Feb-08 2:39
mentorNot Active27-Feb-08 2:39 
GeneralRe: Are child threads of an object destroyed when an object is destroyed. Pin
Bekjong27-Feb-08 2:41
Bekjong27-Feb-08 2:41 
GeneralRe: Are child threads of an object destroyed when an object is destroyed. Pin
pbraun27-Feb-08 9:09
pbraun27-Feb-08 9:09 
GeneralSpeech comparison Pin
Yoyosch27-Feb-08 2:24
Yoyosch27-Feb-08 2:24 
GeneralRe: Speech comparison Pin
mav.northwind27-Feb-08 3:39
mav.northwind27-Feb-08 3:39 
GeneralRe: Speech comparison Pin
Yoyosch27-Feb-08 3:49
Yoyosch27-Feb-08 3:49 
GeneralRe: Speech comparison Pin
Justin Perez27-Feb-08 4:02
Justin Perez27-Feb-08 4:02 
QuestionHow to write properties in design time Pin
El'Cachubrey27-Feb-08 2:15
El'Cachubrey27-Feb-08 2:15 
AnswerRe: How to write properties in design time Pin
Xmen Real 27-Feb-08 2:33
professional Xmen Real 27-Feb-08 2:33 
Generalstore files in a database Pin
Member 366830827-Feb-08 2:13
Member 366830827-Feb-08 2:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.