Solved

Basic's Trim() function in Delphi 1.0?

Posted on 1998-11-07
6
263 Views
Last Modified: 2010-05-18
I would like to know if there is a function like Basic's
Trim() to get rid of spaces in Delphi 1.0?
0
Comment
Question by:poodle
[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
6 Comments
 
LVL 1

Expert Comment

by:ow
ID: 1346021
 Hi poodle,

in unit sysutils you find:

{ Trim trims leading and trailing spaces and control characters from the  given string. }
function Trim(const S: string): string;

{ TrimLeft trims leading spaces and control characters from the given  string. }
function TrimLeft(const S: string): string;

{ TrimRight trims trailing spaces and control characters from the given  string. }
function TrimRight(const S: string): string;

regards
  ow

0
 
LVL 1

Expert Comment

by:EmmDieh
ID: 1346022
ow: that's correct for delphi >= 3 (2?), but not
for Delphi 1.

0
 
LVL 10

Expert Comment

by:viktornet
ID: 1346023
Here is the way to do it in Delphi1,2

as a procedure...

procedure Trim(var Str : string);
begin
  while Str[1] = ' ' do
    Delete(Str, 1,1);
  while Str[Length(str)] = ' ' do
    Delete(Str, Length(Str)-1, 1);
end;

as a function...

function Trim(Str : String):String;
begin
  Result := Str;
  while Result[1] = ' ' do
    Delete(Result, 1,1);
  while Result[Length(Result)] = ' ' do
    Delete(Result, Length(Result)-1, 1);
end;

To use them just do as follows...

var
  S : string;
begin
  S := '   Hello World   ';
  //To use the procedure do this.....
  Trim(s);
  //If you want to use the function just do this...
  S := Trim(s);
  caption := s;
end;

Cheers,
Viktor
0
Industry Leaders: 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 1

Expert Comment

by:ow
ID: 1346024
 Hi poodle,

I am really sorry, but my answer is not correct.
As Emmdieh says, these routines are not implemernted in Delphi 1.
Unfortunatley I looked at the wrong source file.

So please reject my answer and give the points to Victor, as he has shown the right way.

Regards
  ow
0
 

Author Comment

by:poodle
ID: 1346025
I rejected ow, but how can I accept vitornet's answer?
0
 
LVL 10

Accepted Solution

by:
viktornet earned 50 total points
ID: 1346026
You can now accept my answer... 10x

Cheers,
Viktor
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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month4 days, 15 hours left to enroll

635 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