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

String Builder, appending carriage return

Hi,

I am trying to append a carriage return to my string using the string
builder class, but when I do this the string ends up containing "13".
I tried this multiple ways like so

sb->Append('\r');

and also

sb->Append(System::Windows::Forms::Keys::Enter);

and lastly i tried

sb->Append((char)13);

I also tried that last one without the char type casting and my string
still contains 13 instead of a code for carriage return. Any ideas??

Apr 23 '06 #1
11 8420
I just realized this function is expecting a string, so a character
constant will not work. if you do

sb->Append("\r");

it will append a carriage return code.

Apr 23 '06 #2
The Rain,

A cariage return are two codes, A carriage "\c" and a return "\r"
ASC 13 10

I hope this help

Cor
"TheRain" <co**********@gmail.com> schreef in bericht
news:11*********************@g10g2000cwb.googlegro ups.com...
I just realized this function is expecting a string, so a character
constant will not work. if you do

sb->Append("\r");

it will append a carriage return code.

Apr 24 '06 #3
> A cariage return are two codes, A carriage "\c" and a return "\r"
ASC 13 10


or try:
sb.Append(Environment.NewLine);

Markus
Apr 24 '06 #4
Cor Ligthert [MVP] <no************@planet.nl> wrote:
A cariage return are two codes, A carriage "\c" and a return "\r"
ASC 13 10


No, that's carriage return and line feed. Carriage return ("\r") is 13,
and line feed ("\n") is 10. The two of them are used together for the
Windows line ending.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 24 '06 #5
TheRain <co**********@gmail.com> wrote:
I just realized this function is expecting a string, so a character
constant will not work.


There *is* a method which accepts a char though. Perhaps the problem is
that it's expecting a .NET char (i.e. Unicode) rather than a C/C++
char. Did you try:

sb->Append (L'\r');

?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 24 '06 #6
hey... I just started messing with .net so I'm not even sure what that
L does.. is that some kind of typecasting?? I keep seeing S used like
this in MSDN articles. Anyway, I just attempted the sb->Append(L'r');
and it still gives me 13 instead at the output.

thanks for all of the thoughts and comments, maybe some others will
find this useful as well.

Apr 24 '06 #7
As an aside, "\n" is the Unix equivalent. No CR.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Cor Ligthert [MVP] <no************@planet.nl> wrote:
A cariage return are two codes, A carriage "\c" and a return "\r"
ASC 13 10


No, that's carriage return and line feed. Carriage return ("\r") is 13,
and line feed ("\n") is 10. The two of them are used together for the
Windows line ending.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Apr 24 '06 #8
TheRain <co**********@gmail.com> wrote:
hey... I just started messing with .net so I'm not even sure what that
L does.. is that some kind of typecasting?? I keep seeing S used like
this in MSDN articles.
I *think* S is used for a managed string, but to be honest I don't know
about managed chars. I don't know a lot about MC++ :(
Anyway, I just attempted the sb->Append(L'r');
and it still gives me 13 instead at the output.


Right - I think you'd have to find out what the equivalent of a .NET
char is in MC++ to work it out for sure.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 24 '06 #9
Hello, TheRain!

T> I am trying to append a carriage return to my string using the string
T> builder class, but when I do this the string ends up containing "13".
T> I tried this multiple ways like so

If you're under .NET you can do sb->AppendLine("sometext");
Environment.NewLine will be appended after the text.

AppenLine internally uses this.Append(Environment.NewLine);

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
Apr 25 '06 #10
Vadym Stetsyak <va*****@ukr.net> wrote:
Hello, TheRain!

T> I am trying to append a carriage return to my string using the string
T> builder class, but when I do this the string ends up containing "13".
T> I tried this multiple ways like so

If you're under .NET you can do sb->AppendLine("sometext");
Environment.NewLine will be appended after the text.

AppenLine internally uses this.Append(Environment.NewLine);


Do you mean "If you're under .NET 2.0"? AppendLine is new to 2.0.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 25 '06 #11
Hello, Jon!

JSC> Do you mean "If you're under .NET 2.0"? AppendLine is new to 2.0.

Yes, I missied to mention 2.0 :8-))).

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
Apr 26 '06 #12

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

Similar topics

2
by: Karuppasamy | last post by:
Hi I am using a variable of StringBuilder to form a string. After appending a string of value like this {\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Verdana;}}
2
by: José Joye | last post by:
Hello, I was wondering if there is a method that exists to replace multi-spaces within a string with single-space. eg: "12 3 4 56" --> "12 3 4 56" I think this could be done by...
12
by: Tee | last post by:
String Builder & String, what's the difference. and when to use which ? Thanks.
2
by: P K | last post by:
Hi, I have around 30 fields on a screen each one of which I need to validate. The idea was to have a set of messages to be displayed for all the posiible errors instead of having to show a...
2
by: sean | last post by:
Can anyone tell me how to add a carriage return to a string using vb.net? I need to add two strings with a carrage return together and post to an email message body ie: This gives me an...
18
by: ILCSP | last post by:
Hi, I just started learning Visual Basic (VB.NET 03) and I need to do this small program that will read a text file we get from another company that has survey data, parse it and flatten it out and...
26
by: Hardy Wang | last post by:
Hi all, I know it is better to handle large string with a StringBuilder, but how does StringBuilder class improve the performance in the background? Thanks! -- WWW:...
7
by: simonZ | last post by:
I have array variable transfer: String transfer which has some data Than I would like to convert this data into string: Which way is more efficient: StringBuilder rezult=new StringBuilder(); ...
13
by: xzzy | last post by:
None of the following properly do the VB.net double quote conversion because all of the following in csharp convert to \" instead of just a double quote: " I have tried: char...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...

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.