Solved

program that reverses text

Posted on 2007-11-14
15
189 Views
Last Modified: 2010-04-21
Does anyone know the delphi code to reverse a line of text that I enter in it like so:

-I type this line

it becomes

-enil siht epyt i

thx in advance
0
Comment
Question by:PeterdeB
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 4
  • +1
15 Comments
 
LVL 19

Expert Comment

by:MerijnB
ID: 20283923
if you use the unit StrUtils there is a function called ReverseString() you can use.
If you want to keep the '-' in front use something like:

uses StrUtils;

...

function Reverse(InStr: string): string;
begin
 result := '';

 if Length(InStr) = 0 then
  exit;

 if InStr[1] = '-' then
 begin
  result := '-';
  Delete(InStr, 1, 1);
 end;

 result := LowerCase(result + ReverseString(InStr));
end;
0
 

Author Comment

by:PeterdeB
ID: 20284297
Hey thank you, i went to do a search for this, but it is included with delphi [the unit]. I am trying to make it work now
0
 

Author Comment

by:PeterdeB
ID: 20284306
procedure TForm1.Button1Click(Sender: TObject);
var
line1, line2: string;
begin
line1:= edit1.Text;
Reverse (line1);
end;

it compiles correctly but does not change the text
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 19

Accepted Solution

by:
MerijnB earned 250 total points
ID: 20284321
like this:

procedure TForm1.Button1Click(Sender: TObject);
var
line1, line2: string;
begin
line1:= edit1.Text;
line1 := Reverse (line1);
end;
0
 
LVL 25

Expert Comment

by:imitchie
ID: 20284947
or..

procedure TForm1.Button1Click(Sender: TObject);
var
line1, line2: string;
begin
line1:= Reverse (edit1.Text);
end;
0
 
LVL 25

Expert Comment

by:imitchie
ID: 20284958
actually, i think you typed the "-' in your question misleading MerijnB. this is enough

line1:= ReverseString(edit1.Text);
0
 
LVL 13

Assisted Solution

by:rfwoolf
rfwoolf earned 250 total points
ID: 20288190
errrrrrr what the Author wants you to tell him/her is this:

procedure TForm1.Button1Click(Sender: TObject);
var
  line1, string;
begin
  line1:= edit1.Text;
  line1 := Reverse (line1);
 ***** Edit1.text := line1;  <--- This line!
end;

Or am I off the mark?
0
 
LVL 19

Expert Comment

by:MerijnB
ID: 20335159
huh? strange answer to accept ??
0
 
LVL 13

Expert Comment

by:rfwoolf
ID: 20335204
I see... PeterdeB, although you have accepted the correct solution because what I typed was the correct code that would compile and work, I am undeserving of (all?) the points.
I will not personally object if someone goes to admin to get the points re-assigned. Although it was probably an innocent mistake, it is not fair :p
0
 

Author Closing Comment

by:PeterdeB
ID: 31409229
Sowwy for my short comments and feedback my girlfriend just left me:(
0
 
LVL 13

Expert Comment

by:rfwoolf
ID: 20349818
Thanks guys. That's much better. Don't you agree, MerjinB?
0
 
LVL 19

Expert Comment

by:MerijnB
ID: 20349833
yeps :)

I don't really mind about the points, more like a comment to the question asker to pay attention when assigning the points
0
 

Author Comment

by:PeterdeB
ID: 20462299
heey guys sowwy like I said I had too much things on my mind and still have tell me  if I stil need to change anything :(
0
 
LVL 13

Expert Comment

by:rfwoolf
ID: 20463504
Hey thanks PeterdeB. Sorry about your girlfriend. It's all good now :) Thanks. Hope to see you again.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question