Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 200
  • Last Modified:

program that reverses text

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
PeterdeB
Asked:
PeterdeB
  • 4
  • 4
  • 4
  • +1
2 Solutions
 
MerijnBSr. Software EngineerCommented:
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
 
PeterdeBAuthor Commented:
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
 
PeterdeBAuthor Commented:
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
MerijnBSr. Software EngineerCommented:
like this:

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

procedure TForm1.Button1Click(Sender: TObject);
var
line1, line2: string;
begin
line1:= Reverse (edit1.Text);
end;
0
 
imitchieCommented:
actually, i think you typed the "-' in your question misleading MerijnB. this is enough

line1:= ReverseString(edit1.Text);
0
 
rfwoolfCommented:
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
 
MerijnBSr. Software EngineerCommented:
huh? strange answer to accept ??
0
 
rfwoolfCommented:
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
 
PeterdeBAuthor Commented:
Sowwy for my short comments and feedback my girlfriend just left me:(
0
 
rfwoolfCommented:
Thanks guys. That's much better. Don't you agree, MerjinB?
0
 
MerijnBSr. Software EngineerCommented:
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
 
PeterdeBAuthor Commented:
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
 
rfwoolfCommented:
Hey thanks PeterdeB. Sorry about your girlfriend. It's all good now :) Thanks. Hope to see you again.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 4
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now