Solved

Trim String

Posted on 2000-04-03
3
320 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now