473,327 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

CR char eliminated

I'm sending a string (xml string) to web service as a parameter. One of the
tags in the xml string is the address field and the values of this tag have
LF + CR chars. When I receive the string in the web service method the values
have only the LF chars.
What's happening here?
Nov 23 '05 #1
6 3214
Hello,

Before sending to the web service class, the paramter string will be
encoded and decoded, and the CR was lost during the procedure. To get
around the issue, you can consider following ways;

1. When get the string in web service, search for LF in the string and
replace with LF+CR.
2. Before send the string to web service, change its encoding to Unicode.
For example:

Encoding ascii = Encoding.ASCII;
Encoding unicode = Encoding.Unicode;

byte[] asciiBytes = ascii.GetBytes(MyString);
byte[] unicodeBytes = Encoding.Convert(ascii,unicode, asciiBytes);

char[] unicodeChars = new char[unicode.GetCharCount(unicodeBytes, 0,
unicodeBytes.Length)];
unicode.GetChars(unicodeBytes, 0, unicodeBytes.Length, unicodeChars, 0);
string unicodeString = new string(unicodeChars)

In this way, the string will be pass in Unicode encoding the CR won't be
lost.

On Web service side, we can use the Uncode string directly, or convert it
to ASCII back:

Encoding ascii = Encoding.ASCII;
Encoding unicode = Encoding.Unicode;

byte[] unicodeBytes = unicode.GetBytes(MyString);
byte[] asciiBytes = Encoding.Convert(unicode, ascii, unicodeBytes);

char[] asciiChars = new char[ascii.GetCharCount(asciiBytes, 0,
asciiBytes.Length)];
ascii.GetChars(asciiBytes, 0, asciiBytes.Length, asciiChars, 0);
string asciiString = new string(asciiChars);

Hope this help,

Luke
Nov 23 '05 #2
Hello,

Before sending to the web service class, the paramter string will be
encoded and decoded, and the CR was lost during the procedure. To get
around the issue, you can consider following ways;

1. When get the string in web service, search for LF in the string and
replace with LF+CR.
2. Before send the string to web service, change its encoding to Unicode.
For example:

Encoding ascii = Encoding.ASCII;
Encoding unicode = Encoding.Unicode;

byte[] asciiBytes = ascii.GetBytes(MyString);
byte[] unicodeBytes = Encoding.Convert(ascii,unicode, asciiBytes);

char[] unicodeChars = new char[unicode.GetCharCount(unicodeBytes, 0,
unicodeBytes.Length)];
unicode.GetChars(unicodeBytes, 0, unicodeBytes.Length, unicodeChars, 0);
string unicodeString = new string(unicodeChars)

In this way, the string will be pass in Unicode encoding the CR won't be
lost.

On Web service side, we can use the Uncode string directly, or convert it
to ASCII back:

Encoding ascii = Encoding.ASCII;
Encoding unicode = Encoding.Unicode;

byte[] unicodeBytes = unicode.GetBytes(MyString);
byte[] asciiBytes = Encoding.Convert(unicode, ascii, unicodeBytes);

char[] asciiChars = new char[ascii.GetCharCount(asciiBytes, 0,
asciiBytes.Length)];
ascii.GetChars(asciiBytes, 0, asciiBytes.Length, asciiChars, 0);
string asciiString = new string(asciiChars);

Hope this help,

Luke
Nov 23 '05 #3
Thanks for your response.
It looks to me that this is a bug, I don't understand the rational to change
lfcr to lf otherwise.

"[MSFT]" wrote:
Hello,

Before sending to the web service class, the paramter string will be
encoded and decoded, and the CR was lost during the procedure. To get
around the issue, you can consider following ways;

1. When get the string in web service, search for LF in the string and
replace with LF+CR.
2. Before send the string to web service, change its encoding to Unicode.
For example:

Encoding ascii = Encoding.ASCII;
Encoding unicode = Encoding.Unicode;

byte[] asciiBytes = ascii.GetBytes(MyString);
byte[] unicodeBytes = Encoding.Convert(ascii,unicode, asciiBytes);

char[] unicodeChars = new char[unicode.GetCharCount(unicodeBytes, 0,
unicodeBytes.Length)];
unicode.GetChars(unicodeBytes, 0, unicodeBytes.Length, unicodeChars, 0);
string unicodeString = new string(unicodeChars)

In this way, the string will be pass in Unicode encoding the CR won't be
lost.

On Web service side, we can use the Uncode string directly, or convert it
to ASCII back:

Encoding ascii = Encoding.ASCII;
Encoding unicode = Encoding.Unicode;

byte[] unicodeBytes = unicode.GetBytes(MyString);
byte[] asciiBytes = Encoding.Convert(unicode, ascii, unicodeBytes);

char[] asciiChars = new char[ascii.GetCharCount(asciiBytes, 0,
asciiBytes.Length)];
ascii.GetChars(asciiBytes, 0, asciiBytes.Length, asciiChars, 0);
string asciiString = new string(asciiChars);

Hope this help,

Luke

Nov 23 '05 #4
Thanks for your response.
It looks to me that this is a bug, I don't understand the rational to change
lfcr to lf otherwise.

"[MSFT]" wrote:
Hello,

Before sending to the web service class, the paramter string will be
encoded and decoded, and the CR was lost during the procedure. To get
around the issue, you can consider following ways;

1. When get the string in web service, search for LF in the string and
replace with LF+CR.
2. Before send the string to web service, change its encoding to Unicode.
For example:

Encoding ascii = Encoding.ASCII;
Encoding unicode = Encoding.Unicode;

byte[] asciiBytes = ascii.GetBytes(MyString);
byte[] unicodeBytes = Encoding.Convert(ascii,unicode, asciiBytes);

char[] unicodeChars = new char[unicode.GetCharCount(unicodeBytes, 0,
unicodeBytes.Length)];
unicode.GetChars(unicodeBytes, 0, unicodeBytes.Length, unicodeChars, 0);
string unicodeString = new string(unicodeChars)

In this way, the string will be pass in Unicode encoding the CR won't be
lost.

On Web service side, we can use the Uncode string directly, or convert it
to ASCII back:

Encoding ascii = Encoding.ASCII;
Encoding unicode = Encoding.Unicode;

byte[] unicodeBytes = unicode.GetBytes(MyString);
byte[] asciiBytes = Encoding.Convert(unicode, ascii, unicodeBytes);

char[] asciiChars = new char[ascii.GetCharCount(asciiBytes, 0,
asciiBytes.Length)];
ascii.GetChars(asciiBytes, 0, asciiBytes.Length, asciiChars, 0);
string asciiString = new string(asciiChars);

Hope this help,

Luke

Nov 23 '05 #5
This is not only with Web service, but also all XML processor which treat
the character sequence Carriage Return-Line Feed (CRLF) like single CR or
LF characters. All are reported as a single LF character. XML is
cross-platform standard, this is designed for the compatibility with
others, such as Unix.

Hope this help,

Luke
Nov 23 '05 #6
This is not only with Web service, but also all XML processor which treat
the character sequence Carriage Return-Line Feed (CRLF) like single CR or
LF characters. All are reported as a single LF character. XML is
cross-platform standard, this is designed for the compatibility with
others, such as Unix.

Hope this help,

Luke
Nov 23 '05 #7

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

Similar topics

11
by: Pontus F | last post by:
Hi I am learning C++ and I'm still trying to get a grip of pointers and other C/C++ concepts. I would appreciate if somebody could explain what's wrong with this code: ---begin code block--- ...
2
by: Neil Zanella | last post by:
Hello, Consider the following program. There are two C style string stack variables and one C style string heap variable. The compiler may or may not optimize the space taken up by the two stack...
2
by: Peter Nilsson | last post by:
In a post regarding toupper(), Richard Heathfield once asked me to think about what the conversion of a char to unsigned char would mean, and whether it was sensible to actually do so. And pete has...
9
by: Sathyaish | last post by:
I noticed that gets() reads into the buffer even if the you've not allocated enough memory. For instance, if you do: char *str=(char*)malloc(sizeof(char)); printf("Enter something about...
11
by: QQ | last post by:
I know a char is 2 bytes, the conversion is like byte byte_array = new byte; //Allocate double mem as that of char then for each char do byte = (byte) char & 0xff byte = (byte)( char >> 8 &...
13
by: eiaks | last post by:
Hello, I want to print a table of characters and their values for my system like 65: A 66: B aso. starting from 0 to 255. Am I rigth that I should use an unsigned char for this,...
6
by: kjm424 | last post by:
I'm wondering if someone can shed some light on a decision made in the C++ standard. It would seem that when passing a temporary into a function that takes a const reference, the copy...
43
by: TheDrunkenDead | last post by:
Hello, just wondering how I would assign a char array of four elements to the four bytes used in an int. As of right now my code is: cNameSize = (char)((void)NameSize); cFileSize =...
14
by: Javier | last post by:
Hello, in which cases is it better the use of "const char*" to "string" (or even const string &). I mean, in STL (http://www.sgi.com/tech/stl/hash_map.html) I see: hash_map<const char*, int,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.