Link to home
Start Free TrialLog in
Avatar of c-prompt
c-prompt

asked on

Using string pos

Hello, I need to verify the position of two strings in a list of strings from left to right, for example, if the pos " $" comes before the pos "#" in a TstringList then the argument will not pass.

it needs be something like this.

List:= TStringList.create;
List.add('$ #');
List.add('# $');
List.add('$ #');
For I := 0 To List.Count -1 Do
Begin
   S:= List.Strings[I];
   If (Pos('#',S)>0)AND(Pos('$',S)>0) THEN
Begin
 Do Arguement


The argument should only pass if the pos '#' comes before the pos "$" from left to right for every string in the TstringList.

Thankyou.


Avatar of kretzschmar
kretzschmar
Flag of Germany image

var
  pos#,
  pos$ : Integer;
  s : String
begin
  For I := 0 To List.Count -1 Do
  Begin
     S:= List.Strings[I];
     Pos# := Pos('#',S);
     pos$ := Pos('$',S)
     If  Pos#<pos$ THEN
    Begin
     Do Arguement

meikl ;-)

ASKER CERTIFIED SOLUTION
Avatar of kretzschmar
kretzschmar
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of c-prompt
c-prompt

ASKER

Thanks for the quick response.
If there is a possibility that '$' doesn't appear at all in a particular string AND you want to allow that to pass then you want something like:

If  (pos# > 0) and ((pos# < pos$) OR (pos$ = 0)) THEN