472,952 Members | 2,302 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,952 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 8339
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.