473,396 Members | 1,833 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,396 software developers and data experts.

StringBuilder and C#

What is the best way of creating the staement below in C#? StringBuilder will not accept the string as stated. I've tried several variations of string concatenation but still get errors
StringBuilder postData = new StringBuilder("<CABDETAILS CabNumber=""43877"" CabSKU=""6633"" ExpDate=""0106"" Postal=""78052"" />"); Dont want to create a separate xml file

Thank
Jacob
Nov 15 '05 #1
5 6758
You basicly had it, you just needed the escape character
System.Text.StringBuilder postData = new
System.Text.StringBuilder("<CABDETAILS CabNumber=\"43877\" CabSKU=\"6633\"
ExpDate=\"0106\" Postal=\"78052\" />");
"Jacob" <mi****@msn.com> wrote in message
news:0C**********************************@microsof t.com...
What is the best way of creating the staement below in C#? StringBuilder will not accept the string as stated. I've tried several variations of
string concatenation but still get errors. StringBuilder postData = new StringBuilder("<CABDETAILS CabNumber=""43877"" CabSKU=""6633"" ExpDate=""0106"" Postal=""78052"" />");
Dont want to create a separate xml file.
Thanks
Jacob

Nov 15 '05 #2
Thanks Kirk
What if I have something like "Boston\ivr" in the expression string? Since "\" is the escape character, How do I handle that
Jaco

Nov 15 '05 #3
Jacob wrote:

Thanks Kirk-
What if I have something like "Boston\ivr" in the expression string? Since "\" is the escape character, How do I handle that?
Jacob


"Boston\\ivr"
Nov 15 '05 #4
Jacob,

try using the @ symbol - it causes the compiler to ignore escape characters.

Something like this to create and initialize the StringBuilder object, then
extract the characters to investigate:

StringBuilder str = new StringBuilder( @"Boston\ivr");
char [] chrs = str.ToString().ToCharArray();

regards
roy fine
"Jacob" <mi****@msn.com> wrote in message
news:FF**********************************@microsof t.com...
Thanks Kirk-
What if I have something like "Boston\ivr" in the expression string? Since "\" is the escape character, How do I handle that? Jacob

Nov 15 '05 #5
Jacob <mi****@msn.com> wrote:
What if I have something like "Boston\ivr" in the expression string?
Since "\" is the escape character, How do I handle that?


See http://www.pobox.com/~skeet/csharp/faq/#escapes

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #6

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

Similar topics

37
by: Kevin C | last post by:
Quick Question: StringBuilder is obviously more efficient dealing with string concatenations than the old '+=' method... however, in dealing with relatively large string concatenations (ie,...
20
by: Alvin Bruney | last post by:
On the advice of a user, I've timed stringbuilder v string. Here are the results. Here are the numbers: Total # queries 3747 Time in Milliseconds StringBuilder: String...
0
by: Mo | last post by:
I am having problem with marshaling struct in C#. //the original C++ struct typedef struct _tagHHP_DECODE_MSG { DWORD dwStructSize; // Size of decode structure. TCHAR ...
11
by: deko | last post by:
I need to loop through a string and remove all characters except numbers or letters. I am getting an ArgumentOutOfRangeException: "Index was out of range. Must be non-negative and less than the...
2
by: Peter | last post by:
Hi, A newbie question .. I want to use an array of length 4 while each array element is a string of 40 chars. I typed .. StringBuilder title = new StringBuilder(40);
9
by: Peter Row | last post by:
Hi, I know this has been asked before, but reading the threads it is still not entirely clear. Deciding which .Replace( ) to use when. Typically if I create a string in a loop I always use a...
12
by: Richard Lewis Haggard | last post by:
I thought that the whole point of StringBuilder was that it was supposed to be a faster way of building strings than string. However, I just put together a simple little application to do a...
2
by: m00nm0nkey | last post by:
Ok well i thought i'd try a different approach, so what I'm now trying is appending 50,000 lines from the collection to a stringbuilder, and then writing that entire stringbuilder to a file. ...
5
by: pantagruel | last post by:
Hi, It is generally stated that stringbuilder should be used instead of just concatenating strings with the plus operator. That's fine enough what I'm wondering in cases I have: String S =...
34
by: raylopez99 | last post by:
StringBuilder better and faster than string for adding many strings. Look at the below. It's amazing how much faster StringBuilder is than string. The last loop below is telling: for adding...
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
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
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...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.