Link to home
Start Free TrialLog in
Avatar of nafa2221
nafa2221

asked on

Trim String

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!
ASKER CERTIFIED SOLUTION
Avatar of JoeBooth
JoeBooth

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nafa2221
nafa2221

ASKER

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
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