By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,930 Members | 1,487 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,930 IT Pros & Developers. It's quick & easy.

String Builder, appending carriage return

P: n/a
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
Share this Question
Share on Google+
11 Replies


P: n/a
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

P: n/a
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

P: n/a
> 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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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.