Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Trim String

Posted on 2000-04-03
3
Medium Priority
?
332 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 200 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Integration Management Part 2
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

782 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