How to do this the fastest way?

后端 未结 1 1063
一向
一向 2021-01-16 13:18

I need to find out how many time one word appears in the string, but the catch is that the word you need to find can have spaces in between, for example you want to see how

相关标签:
1条回答
  • 2021-01-16 14:07

    You could check the array twice, on the first run trough it remove all spaces. On the second one use a compare function like this(x is the array in which you search, y is the sub-string you are searching for and i is the current element you are checking):

    function compare(var x,y:myarray; i:integer):boolean;
    var l:integer;
    Begin
      compare:=false;
      for l:=1 to length(y) do Begin
        if x[i+l] <> y[l] then Exit;
      End;
      compare:=true;
    End;
    

    on each element of your array.

    0 讨论(0)
提交回复
热议问题