Solved

Trim String

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month8 days, 10 hours left to enroll

615 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