Query

Chad

New Member
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
 

Vivek

New Member
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
Thanks Chad! But I want to count the number of occurrences of that string also.
 

Chad

New Member
Remove 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.
 
Last edited:

Vivek

New Member
Remove 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.
Thanks a lot Chad
 

Cringer

ProgressTalk.com Moderator
Staff member
If you can guarantee that a certain character doesn't appear in the string then you can do something similar to below:
Code:
define variable MyString as longchar   no-undo initial 'JP454554JP3223'.

message num-entries(replace(MyString,"JP","|"),"|") - 1
    view-as alert-box info buttons ok.
 

andre42

Member
Remove the string each time you find it in the variable and count the number of times you remove the string
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.
 
Top