473,394 Members | 1,794 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,394 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 3219
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...

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.