469,645 Members | 1,546 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,645 developers. It's quick & easy.

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 7680
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Karuppasamy | last post: by
2 posts views Thread by P K | last post: by
26 posts views Thread by Hardy Wang | last post: by
7 posts views Thread by simonZ | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.