Embedded return chars in a string


I'm trying to embed carriage returns in a Delphi long string and then printing it out in the following manner (in a console app):

var
    aString : String;
begin
    aString := 'Hello' + Chr(13) + 'World';
    Writeln(aString);
end.

But instead of getting the word "Hello" in one line and "World" on another, I get some garbled text all on one line, e.g. "HeWorld".  Does writeln not interpret carriage returns within a text?  Or is 13 the wrong ASCII value for a carriage return?


Thanks,

Ap9
ap9Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rwilson032697Commented:
You need to add CHR(10) as well.

You can also use #13 and #10 as shorthand notations.

Cheers,

Raymond.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RBertoraCommented:
Try this:

var
    aString : String;
begin
    aString := 'Hello' + #10#13 + 'World';
    Write(aString);
end.


Notice you use Write not writeln.

Rob ;-)
0
sburckCommented:
A couple of elaborations:  

1)  #13 is a carriage return, #10 is a line feed, which is what will separate them on two lines.

2)  Even shorterhand is:
    astring := 'Hello'#10#13'World';

3)  This works with both write and writeln, writeln appends a CR/LF at the end of the string as well.
0
ap9Author Commented:
Thanks to all that responded!  The missing linefeed was the trick!

I had written a test program that displayed the the ASCII value of key presses, and hitting ENTER made it display a "13", so I had thought that was all I needed.  I guess not.

Thanks again!


AP9
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.