Thanks Chad! But I want to count the number of occurrences of that string also.I would COPY-LOB the contents of the file to a variable and then just use the INDEX() function to find the string in the variable
def var lcFileContent as longchar no-undo.
def var cStringToFind as character no-undo.
def var iCount as integer no-undo.
assign
lcFileContent = "how many times can we find the 'an' string in this sentance?"
cStringToFind = "an"
iCount = 0.
do while index(lcFileContent,cStringToFind) > 0:
assign
substring(lcFileContent,index(lcFileContent,cStringToFind),length(cStringToFind)) = ""
iCount = iCount + 1.
end.
message iCount.
Thanks a lot ChadRemove the string each time you find it in the variable and count the number of times you remove the string
Code:def var lcFileContent as longchar no-undo. def var cStringToFind as character no-undo. def var iCount as integer no-undo. assign lcFileContent = "how many times can we find the 'an' string in this sentance?" cStringToFind = "an" iCount = 0. do while index(lcFileContent,cStringToFind) > 0: assign substring(lcFileContent,index(lcFileContent,cStringToFind),length(cStringToFind)) = "" iCount = iCount + 1. end. message iCount.
You may want to replace the string with some arbitrary characters instead... so you dont create a false result if you inadvertently create a new string accidentally when removing characters.
define variable MyString as longchar no-undo initial 'JP454554JP3223'.
message num-entries(replace(MyString,"JP","|"),"|") - 1
view-as alert-box info buttons ok.
Sounds pretty inefficient. The INDEX function has an optional third parameter which tells it where to start the search. So you just add 1 to the last returned value and call it again until no more matches are found.Remove the string each time you find it in the variable and count the number of times you remove the string