Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Char from set in string? (https://www.delphipraxis.net/172479-char-set-string.html)

WojTec 6. Jan 2013 11:34

Delphi-Version: 2010

Char from set in string?
 
Delphi-Quellcode:
const
  ParamSeps = ['=', ':', '?'];
Delphi-Quellcode:
P := Pos('=', AIn);
if P = 0 then
begin
  P := Pos(':', AIn);
 
  if P = 0 then
    P := Pos('?', AIn)
  ;
end;
Is possible to check if char is in text using above set instead if-block and Pos()?

p80286 6. Jan 2013 12:01

AW: Char from set in string?
 
An other way might be
Delphi-Quellcode:
i:=0;
repeat
  inc(i,1);
until (i>length(aIn)) or (aIn[i] in ParamSeps);
if I>length(aIn) then //sepchar found
K-H

Bummi 6. Jan 2013 12:11

AW: Char from set in string?
 
Delphi-Quellcode:
const
  ParamSeps = ['=', ':', '?'];

Function SetCharPos(Const s:String):Integer;
var
 i:Integer;
begin
  Result := 0;
  i := 1;
  while (Result=0) and (i<=Length(s)) do
    begin
       if s[i] in ParamSeps then Result := i
       else inc(i);
    end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
   Caption := IntToStr(SetCharPos('That?'))
end;

WojTec 6. Jan 2013 13:21

Re: Char from set in string?
 
O, quite simple, thanks :)


Alle Zeitangaben in WEZ +1. Es ist jetzt 19:29 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz