Solved

Trim String

Posted on 2000-04-03
3
324 Views
Last Modified: 2010-04-04
I need to trim a string. The string is something like it is below.

Welcome, Brian!

I need to trim that so it only has brian, the name may vary in lenght and there may sometimes be comments after the ! so I will need to trim everything after the ! and then !. I also need to trim the Welcome,. Thanks!
0
Comment
Question by:nafa2221
3 Comments
 
LVL 1

Accepted Solution

by:
JoeBooth earned 50 total points
ID: 2681721
Although what you are describing isn't really a trim function, try the following:

function ExtractName(cStr:string):string;
var
  x : integer;
begin
  x := pos('!',cStr);
  if x >0
  then cStr := copy(cStr,1,x-1);
  x := pos(',',cStr);
  if x > 0
  then cStr := trim(copy(cStr,x+1,999));
  result := cStr;
end;
0
 

Author Comment

by:nafa2221
ID: 2681729
okay, I try to use the function as below

fullwindowtext := extractname(fullwindowtext);

and I get an error about strings not being compatible with arrays. Thanks
0
 

Expert Comment

by:apries
ID: 2681730
Hi,

this example does the trimming you
want:

var
   MYSTRING, NEWSTRING : STRING;

begin
     MYSTRING := 'Welcome, Brian! abcd';

     NEWSTRING := (COPY (MYSTRING, POS (' ', MYSTRING), (POS('!', MYSTRING) - POS (' ', MYSTRING))));
end;


Greetings, Alex
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

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 my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

821 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