Easy to Create, Easy to Change - Easy to use!

Function::String

StringFind

StringFind("StringToSearch","TextToSearchFor") StringFind("This is a test","test") . retval := StringFind(FieldToSearch,Search) . StringFind("Hello World in the world", "world", 0, "exact") return 19 StringFind("Hello World in the world", "world", 0, "count") returns 2 StringFind("Hello World in the world", "Mars", 0, "count") return 0

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.


Parameters


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.

Returns/Result


Integer: Postion of Substring in string. 0 if no match. Will be changed to the count of substring in string.

Examples


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.

Reference

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.

See Also


StringBetween()

StringTo()

StringFrom()
MemoStringBetween()
MemoStringTo()
MemoStringFrom()

On the forum about StringFind

On the blog about StringFind

New Function in 8 - StringFind() - Check if a string is part of another string (Ver. 8.0.0.1022)

Returns start position of StringToFind i.e larger than 0 if a string is part of a text. Returns 0 if it isn't.int StringFind(StringToSearch,StringTofind) It is a complimentary function to *string* which is a simply boolean function.<...

Product: Dataease [{8}]FIVE. Written by DataEase 11/11/11 at 10:32:10