String Builder, appending carriage return

T

TheRain

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??
 
T

TheRain

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.
 
C

Cor Ligthert [MVP]

The Rain,

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

I hope this help

Cor
 
J

Jon Skeet [C# MVP]

Cor Ligthert said:
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.
 
J

Jon Skeet [C# MVP]

TheRain said:
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');

?
 
T

TheRain

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.
 
K

Kevin Spencer

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.
 
J

Jon Skeet [C# MVP]

TheRain said:
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.
 
V

Vadym Stetsyak

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
 
J

Jon Skeet [C# MVP]

Vadym Stetsyak said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top