1 2 3 4 5 6 7 8 9 | function OccurrencesOfChar( const S: string ; const C: char ): integer ; var i: Integer ; begin result := 0 ; for i := 1 to Length(S) do if S[i] = C then inc(result); end ; |
字串(String)計數
1 2 3 4 5 6 7 8 9 10 11 12 | function Occurrences( const Substring, Text: string ): integer ; var offset: integer ; begin result := 0 ; offset := PosEx(Substring, Text, 1 ); while offset <> 0 do begin inc(result); offset := PosEx(Substring, Text, offset + length(Substring)); end ; end ; |
資料來源:
沒有留言:
張貼留言