473,698 Members | 2,751 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3237
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.Unicod e;

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

char[] unicodeChars = new char[unicode.GetChar Count(unicodeBy tes, 0,
unicodeBytes.Le ngth)];
unicode.GetChar s(unicodeBytes, 0, unicodeBytes.Le ngth, unicodeChars, 0);
string unicodeString = new string(unicodeC hars)

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.Unicod e;

byte[] unicodeBytes = unicode.GetByte s(MyString);
byte[] asciiBytes = Encoding.Conver t(unicode, ascii, unicodeBytes);

char[] asciiChars = new char[ascii.GetCharCo unt(asciiBytes, 0,
asciiBytes.Leng th)];
ascii.GetChars( asciiBytes, 0, asciiBytes.Leng th, asciiChars, 0);
string asciiString = new string(asciiCha rs);

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.Unicod e;

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

char[] unicodeChars = new char[unicode.GetChar Count(unicodeBy tes, 0,
unicodeBytes.Le ngth)];
unicode.GetChar s(unicodeBytes, 0, unicodeBytes.Le ngth, unicodeChars, 0);
string unicodeString = new string(unicodeC hars)

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.Unicod e;

byte[] unicodeBytes = unicode.GetByte s(MyString);
byte[] asciiBytes = Encoding.Conver t(unicode, ascii, unicodeBytes);

char[] asciiChars = new char[ascii.GetCharCo unt(asciiBytes, 0,
asciiBytes.Leng th)];
ascii.GetChars( asciiBytes, 0, asciiBytes.Leng th, asciiChars, 0);
string asciiString = new string(asciiCha rs);

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.Unicod e;

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

char[] unicodeChars = new char[unicode.GetChar Count(unicodeBy tes, 0,
unicodeBytes.Le ngth)];
unicode.GetChar s(unicodeBytes, 0, unicodeBytes.Le ngth, unicodeChars, 0);
string unicodeString = new string(unicodeC hars)

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.Unicod e;

byte[] unicodeBytes = unicode.GetByte s(MyString);
byte[] asciiBytes = Encoding.Conver t(unicode, ascii, unicodeBytes);

char[] asciiChars = new char[ascii.GetCharCo unt(asciiBytes, 0,
asciiBytes.Leng th)];
ascii.GetChars( asciiBytes, 0, asciiBytes.Leng th, asciiChars, 0);
string asciiString = new string(asciiCha rs);

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.Unicod e;

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

char[] unicodeChars = new char[unicode.GetChar Count(unicodeBy tes, 0,
unicodeBytes.Le ngth)];
unicode.GetChar s(unicodeBytes, 0, unicodeBytes.Le ngth, unicodeChars, 0);
string unicodeString = new string(unicodeC hars)

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.Unicod e;

byte[] unicodeBytes = unicode.GetByte s(MyString);
byte[] asciiBytes = Encoding.Conver t(unicode, ascii, unicodeBytes);

char[] asciiChars = new char[ascii.GetCharCo unt(asciiBytes, 0,
asciiBytes.Leng th)];
ascii.GetChars( asciiBytes, 0, asciiBytes.Leng th, asciiChars, 0);
string asciiString = new string(asciiCha rs);

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
55553
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--- #include "stdio.h" #include "string.h" void printText(char c){
2
2540
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 variables by placing them at the same address (my g++ compiler does this). Therefore the output of the given C program is compiler dependent. What is worse, the program does not do what its writer most likely intended, since, std::set's find()...
2
3410
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 raised a doubt in my mind on the same issue. Either through ignorance or incompetence, I've been unable to resolve some issues. 6.4.4.4p6 states...
9
5494
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 yourself below:\n\n"); gets(str); printf("\n\n"); puts(str);
11
10195
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 & 0xff) one unsigned char is 1 byte, could anyone tell me the conversion method?
13
2530
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, incrementing it each time? Using an signed char, or just
6
1529
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 constructor must be accessible, even though the copy can be eliminated. Could somebody tell me the reason for this? Section 8.5.3 of the final draft explains the requirement (I think), but with no explanation as to why.
43
3861
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 = (char)((void)FileSize); Where NameSize and FileSize are the integers, and cNameSize and cFileSize are 4 element arrays. This doesn't work.
14
13637
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, hash<const char*>, eqstrmonths; months = 31; I think it is for the use in calls like function("my string"), but, is it really necessary to define funcion(const char*) besides
0
8674
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8603
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9026
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8893
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8861
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3045
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2328
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.