Wikia

Delphi Programming

Parse

2,918pages on
this wiki
Talk0

Parsing Middle from a StringEdit

Uses:

  • StrUtils


Function:

function ParseMiddle(Buffer, Start, Finish: String): String;
var 
  PosStart, PosFinish, Num: Integer;
begin
  PosStart := Pos(Start, Buffer) + Length(Start);
  PosFinish := Posex(Finish, Buffer, PosStart);
  Result := Copy(Buffer, PosStart, PosFinish - PosStart);
end;


Usage:

  ParseMiddle('0123456789','3','8'); //= (4567)

Extract Number from a StringEdit

Function:


function ExtractNumberInString(AContainsNumber: String): String;
var
  CharIndex: Integer;
begin
  Result := '';
  for CharIndex := 1 to length(AContainsNumber) do
    if AContainsNumber[CharIndex] in ['0'..'9'] then
      Result := Result + AContainsNumber[CharIndex];
end;

Usage:

  ShowMessage(ExtractNumberInString('abcd1234defg')); //will show '1234

Around Wikia's network

Random Wiki