[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1231
  • Last Modified:

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.


0
c-prompt
Asked:
c-prompt
  • 2
1 Solution
 
kretzschmarCommented:
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 ;-)

0
 
kretzschmarCommented:
maybe better

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

meikl ;-)
0
 
c-promptAuthor Commented:
Thanks for the quick response.
0
 
cqhallCommented:
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

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now