String Manipulation via Delimiter: Help

Please discuss general Delphi programming topics here.

String Manipulation via Delimiter: Help

Postby delphi7man » October 2nd, 2003, 8:33 pm

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!
delphi7man
Member
Member
 
Posts: 1
Joined: October 2nd, 2003, 8:29 pm

Postby Kambiz » October 3rd, 2003, 4:25 pm

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
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm


Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 7 guests

cron