There is a line (s), in it there are words through a space. It is necessary to put all the words in the array. And count how many times it occurs in a given string (s). I put it in an array.

lastid:=1; j:=1; for i:=1 to length(s) do if (s[i]=' ') then begin a[j]:=copy(s,lastid,i-lastid); lastid:=i+1; inc(j); end; a[j]:=copy(s,lastid,length(s)-lastid+1); 
  • and "And count how many times it occurs in a given line (s)" It is better to find the pos beginning of the word in the line, and delete the characters in the line before this beginning of the word + the length of the word. And do it before pos doesn't return 0 - mbv

1 answer 1

You can make it faster and use not enumeration of all characters, but immediately search for a space through PosEx ('', s, lastid)

  • No, not faster, PosEx is also looking for a brute force, otherwise nothing else :) - strbb
  • It is possible and faster, because it can (if done according to the mind) drag 2-4-8 bytes from the string at once and slap the masks. - drdaeman