Guest User

Untitled

a guest
Jun 30th, 2018
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function StringMatches:Int(text:String,search:String)
  2.     ' --- special comparison function with wildcards and stuff ---
  3.     If search.Length = 0 Return False
  4.     If text = search Return True
  5.    
  6.     'do wildcard check
  7.     'split search term into tokens
  8.     Local tokens:String[] = search.Split("*")
  9.     If tokens.Length = 1 Return False
  10.    
  11.     'do a scan
  12.     Local cursorX:Int = 0
  13.     Local Pos:Int
  14.     For Local index:Int = 0 Until tokens.Length
  15.         Pos = text.Find(tokens[index],cursorX)
  16.         If Pos = -1 Return False
  17.         cursorX = Pos + tokens[index].Length
  18.     Next
  19.     Return True
  20. End Function
  21.  
  22. Local text:String="hello world how are you"
  23. Local search:String = "*world"
  24.  
  25. If StringMatches(text,search)
  26.     Print "YAY MATCH :D '"+text+"' search with '"+search+"'"
  27. Else
  28.     Print "NO MATCH :( '"+text+"' search with '"+search+"'"
  29. EndIf
Add Comment
Please, Sign In to add comment