Question for Encoding.ASCII.GetString

M

mazdotnet

Hi guys,

I'm integrating our systems into another system which returns a
response code after doing a POST

Byte[] responseData = objWebClient.UploadValues(postTo,
objFormPost);
string retVal = Encoding.ASCII.GetString(responseData);

The retVal looks like
<\0C\0o\0n\0t\0a\0c\0t\0I\0d\0>\01\00\04\00\09\02\03\02\05\08\05\0<
\0/\0C\0o\0n\0t\0a\0c\0t\0I\0d\0>\0

When you use the VisualStudio HTML viewer or set it to an
HTML.innerHTML then the value is displayed fine
10409232585

How can I retrieve '10409232585' using code? I tried HtmlDecode with
no lock.

Thanks
M.
 
M

mazdotnet

Hi guys,

I'm integrating our systems into another system which returns a
response code after doing a POST

Byte[] responseData = objWebClient.UploadValues(postTo,
objFormPost);
string retVal = Encoding.ASCII.GetString(responseData);

The retVal looks like
<\0C\0o\0n\0t\0a\0c\0t\0I\0d\0>\01\00\04\00\09\02\03\02\05\08\05\0<
\0/\0C\0o\0n\0t\0a\0c\0t\0I\0d\0>\0

When you use the VisualStudio HTML viewer or set it to an
HTML.innerHTML then the value is displayed fine
10409232585

How can I retrieve '10409232585' using code? I tried HtmlDecode with
no lock.

Thanks
M.

Sorry one more thing to add. When I do it like

string v = "<\0C\0o\0n\0t\0a\0c\0t\0I\0d\0>
\01\00\04\00\09\02\03\02\05\08\05\0<\0/\0C\0o\0n\0t\0a\0c\0t\0I\0d\0>
\0";
Response.Write(v);

It prints '10409232585'

What's happening? Can someone please help?

Thanks
M
 
A

Anthony Jones

mazdotnet said:
Hi guys,

I'm integrating our systems into another system which returns a
response code after doing a POST

Byte[] responseData = objWebClient.UploadValues(postTo,
objFormPost);
string retVal = Encoding.ASCII.GetString(responseData);

The retVal looks like
<\0C\0o\0n\0t\0a\0c\0t\0I\0d\0>\01\00\04\00\09\02\03\02\05\08\05\0<
\0/\0C\0o\0n\0t\0a\0c\0t\0I\0d\0>\0

When you use the VisualStudio HTML viewer or set it to an
HTML.innerHTML then the value is displayed fine
10409232585

How can I retrieve '10409232585' using code? I tried HtmlDecode with
no lock.

Looks to me as though responseData is Unicode not ASCII.
Try:-

string retVal = Encoding.Unicode.GetString(responseData);
 
M

mazdotnet

I'm integrating our systems into another system which returns a
response code after doing a POST
Byte[] responseData = objWebClient.UploadValues(postTo,
objFormPost);
string retVal = Encoding.ASCII.GetString(responseData);
The retVal looks like
<\0C\0o\0n\0t\0a\0c\0t\0I\0d\0>\01\00\04\00\09\02\03\02\05\08\05\0<
\0/\0C\0o\0n\0t\0a\0c\0t\0I\0d\0>\0
When you use the VisualStudio HTML viewer or set it to an
HTML.innerHTML then the value is displayed fine
10409232585
How can I retrieve '10409232585' using code? I tried HtmlDecode with
no lock.

Looks to me as though responseData is Unicode not ASCII.
Try:-

string retVal = Encoding.Unicode.GetString(responseData);

Thank you. It worked.
Maz
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top