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
Solved

program that reverses text

Posted on 2007-11-14
15
187 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
  • 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

789 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