Page 1 of 1

String Manipulation via Delimiter: Help

PostPosted: October 2nd, 2003, 8:33 pm
by delphi7man
Hello all,
Let me introduce my self real fast before I ask my question. I am 20 years old and my name is Jeff. I have been programming in delphi for about a year now and I am now stuck on something I cannot figure out, but the issue may be very simple.

Issue:
I want to extact a portion of text from the end of a string via delimiter(s)
for example "sData:='abunchoftextthatidontwant!@ I want this information'"

I want to take out the part of the string that says "I want this text" via the delimiter "!@". Do any of you know of a way to do this.

Just to give you the idea of the whole picture is that Im trying to create and IRC bot. Thanks much to everybody in advance!

PostPosted: October 3rd, 2003, 4:25 pm
by Kambiz
Hi Jeff,

The following function returns the text after the delimiter.

Code: Select all
function GetTail(const sData: String): String;
const
  Delimiter = '!@';
var
  DelimiterPos: Integer;
begin
  DelimiterPos := Pos(Delimiter, sData);
  if DelimiterPos > 0 then
    Result := Copy(sData,
                   DelimiterPos + Length(Delimiter),
                   Length(sData) - (DelimiterPos - Length(Delimiter)) + 1)
  else // No delimiter
    Result := '';
end;

Hope that it helps.

Cheers,
Kambiz