INDEX ( source , target , starting )A CHARACTER or LONGCHAR expression whose position you want to locate in source. If target does not exist within source, INDEX returns a 0.An integer that specifies at which left-most position in the string to start the search. For example, INDEX("abcdefabcdef","abc",6) returns 7.For this example, you must enter 1, 2, 3, 4, or 5. The INDEX function checks if the digit exists in the string "12345".
DEFINE VARIABLE x AS CHARACTER NO-UNDO FORMAT "9"LABEL "Enter a digit between 1 and 5".DEFINE VARIABLE show AS CHARACTER NO-UNDO FORMAT "x(5)" EXTENT 5LABEL "Literal" INITIAL ["One", "Two", "Three", "Four", "Five"].REPEAT:SET x AUTO-RETURN.IF INDEX("12345",x) = 0 THEN DO:MESSAGE "Digit must be 1,2,3,4, or 5. Try again.".UNDO, RETRY.END.ELSE DISPLAY show[INTEGER(x)].END.This procedure also uses the starting option:
DEFINE VARIABLE positions AS CHARACTER NO-UNDO FORMAT "x(60)".DEFINE VARIABLE sentence AS CHARACTER NO-UNDO FORMAT "x(72)".DEFINE VARIABLE vowel AS CHARACTER NO-UNDO FORMAT "x".DEFINE VARIABLE found AS INTEGER NO-UNDO.DEFINE VARIABLE loop AS INTEGER NO-UNDO.DEFINE VARIABLE start AS INTEGER NO-UNDO.FORM sentence LABEL "Type in a sentence"WITH FRAME topTITLE "This program will tell where the vowels are in a sentence.".SET sentence WITH FRAME top.DO loop = 1 TO 5:ASSIGNpositions = ""vowel = SUBSTRING("aeiou",loop,1)start = 1found = INDEX(sentence,vowel,start).DO WHILE found > 0:ASSIGNpositions = positions + STRING(found) + " "start = found + 1found = INDEX(sentence,vowel,start).END.DISPLAY vowel LABEL "Vowel" positions LABEL "Is found at locations..."WITH 5 DOWN.DOWN.END.
![]()
The INDEX function is double-byte enabled. You can specify target and source strings for the INDEX function that contain double-byte characters.
© 2013 Progress Software Corporation and/or its subsidiaries or affiliates. |