Search a string to find if the substring is find in it. If it is find it will return the position of the first substring.
From 9.0 onwards this function support 4GB large strings both as donor string and sub string. This is mostly theoretical but highlight how much more useful this function now and whey we had to add the new features.
This function can now be used to unwind large texts. You can for instance split up HTML, XML, JSON etc.
StringToSearch; String
The string where we look for substring in.
StringToSearchFor: String
The string we are looking for.
Start Position in String: Number
If you search for a sub-string that can have multiple occurrence the function will give the position of the first so if you want to search "onward" in the string you need to repeat the search and input the position returned+lengt of substring to start after the previous occurrence.
Keyword: String
Currently None,Exact and Count.
None (default): Case insensitive search for word i.e world will find World, WORLD, wORLD etc.
Exact: Search for the sub-string exactly as entered i.e. case sensitive.
Count: Return the number of occurrences of sub-string in string.
Example 1:
Using while loop to run trough large multi-line string and split it up in single lines.
define "retval" text 255.
define "vMemo" memo .
define "start" number .
define "stop" number .
define "linelength" number .
vMemo := getvalue("MyMemo") . -- This is a ExecDQL and we are lazy and read value out of underlying form (execdql)
while StringFind(vMemo,chr(13),start) not = -1 do -- looking for CR if we don't find it we have finished (-1). Start where we stopped last loop
stop :=StringFind(vMemo,chr(13),start) . -- find the actual position of CR.
linelength := stop - start+1 . -- find lenght of line to cut out.
retval := stringReplace(midc(vMemo,start,linelength),chr(10),"") . -- getting rid of LF as we don't need that.
enter a record in SomeData -- enter the line into a table of single lines.
ID := getvalue("ID") ;
Start := temp Start ;
Stop := temp Stop ;
SomeText := retval .
start := stop+2 .
Retval := blank .
message retval .
end
stop := length(vMemo) .
if start <stop then -- check if there is text after last CR
linelength := stop - start .
retval := stringReplace(midc(vMemo,start,linelength),chr(10),"") .
enter a record in SomeData
ID := getvalue("ID") ;
Start := temp Start ;
Stop := temp Stop ;
SomeText := retval .
end
retval := refreshscreen() . -- simply refresh screen/form to see lines in subform.
Returns start position of StringToFind i.e larger than 0 if a string is part of a text. Returns +1 if it isn't.
int StringFind(StringToSearch,StringTofind)
It is a complimentary function to *string* which is a simply boolean function.
StringFrom()
MemoStringBetween()
MemoStringTo()
MemoStringFrom()
Product: Dataease [{8}]FIVE. Written by DataEase 11/11/11 at 10:32:10