Advertisement
Guest User

Untitled

a guest
Oct 12th, 2013
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.58 KB | None | 0 0
  1. /// Checks whether 'word' is in 'text', but not inside a word.
  2. let isIn (text: string) (word: string) =
  3.     let isSep c = not (Char.IsLetterOrDigit(c))
  4.  
  5.     let mutable index = 0
  6.     let mutable cont = true
  7.  
  8.     while cont && index <> -1 do
  9.         index <- text.IndexOf(word, index, StringComparison.CurrentCultureIgnoreCase)
  10.         if index <> -1 then
  11.             if (index = 0 || isSep text.[index - 1]) && (index + word.Length = text.Length || isSep text.[index + word.Length]) then
  12.                 cont <- false
  13.             else
  14.                 index <- index + 1
  15.     not cont
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement