str := 'abcde,jhedk,kehhd,eieje,dkdkfj'This string has five strings with numbers 1-5. Thus if I want to get the last substring I just have to use selectstr(5,str). Now I want to be able to know the last number of the given string and thus loop through the end to get all substrings. Is there any way to get this number.
Answers
// This function returns the count of elements in the string
// Character is the delimiter you are looking for ','
CharCount := 0; // local Var
CharPos := 0; // local Var
CountingString := ''; // local Var
CountingString := TrimString(String,Character); //Call to 2nd function below
CharPos := STRPOS(String,Character);
REPEAT
CountingString := COPYSTR(CountingString,CharPos+1);
CharCount := CharCount + 1;
CharPos := STRPOS(CountingString,Character);
UNTIL CharPos = 0;
EXIT(CharCount + 1);
TrimString(String : Text[250];Character : Text[1]) TrimmedString : Text[250]
//This removes the Character from the beginning and/or end of the string and returns the trimmed string
TrimmedString := String;
IF (STRPOS(String,Character) = 1) THEN
TrimmedString := COPYSTR(String,2);
IF (COPYSTR(String,STRLEN(String)) = Character) THEN
TrimmedString := COPYSTR(TrimmedString,1,STRLEN(TrimmedString)-1);
Str := 'abcde,jhedk,kehhd,eieje,dkdkfj';
MESSAGE('%1',STRLEN(DELCHR(UPPERCASE(Str),'=','ABCDEFGHIJKLMNOPQRSTUVWXYZ')) + 1);
If your option string contains any other chars besides a-z you should append them to the pattern string.