Ooops
March 05, 2021, 07:05:14 AM

Author Topic: [bmx] Search String Array by N [ 1+ years ago ]  (Read 477 times)

Offline BlitzBot

[bmx] Search String Array by N [ 1+ years ago ]
« on: June 29, 2017, 12:28:42 AM »
Title : Search String Array
Author : N
Posted : 1+ years ago

Description : Basically, this searches an array of strings for strings matching the search pattern (* is the only supported wildcard; I didn't see a need for any others).

I don't know of any problems with this, but I wrote it in about 20 minutes or so (while eating cake!), so if you find a problem, might as well post it and I'll try to fix it.

Requires this: <a href="codearcs8aad.html?code=1650" >SplitString[/url]


Code :
Code: BlitzMax
  1. Function SearchStrings$[]( search$, arr$[] )
  2.     Local clean$ = ""
  3.     Local l$ = ""
  4.     For Local ex% = 0 To search.Length-1
  5.         Local p$ = Chr(search[ex])
  6.         If p = "*" And l = "*" Then Continue
  7.         If p = "*" Then p = "|*|"
  8.         clean :+ p
  9.     Next
  10.     Local s$[] = SplitString( clean, "|" )
  11.    
  12.     Local resn%=arr.Length
  13.     Local bad%[arr.Length]
  14.     memset_(bad,0,arr.Length*4)
  15.    
  16.     For Local ex% = 0 To arr.Length-1
  17.         Local e$ = arr[ex]
  18.         If e = "" Or e = Null Then
  19.             bad[ex] = 1
  20.             resn :- 1
  21.             Continue
  22.         EndIf
  23.         Local from% = 0, find% = 0
  24.        
  25.         For Local i% = 0 To s.Length-1
  26.             Local p$ = s[i]
  27.            
  28.             If p = "*" And i = s.Length-1 Then
  29.                 Continue
  30.             ElseIf p = "*" Then
  31.                 p = s[i+1]
  32.             EndIf
  33.            
  34.             find = e.Find(p,from)
  35.             If find = -1 Or (find > 0 And i = 0 And s[i] <> "*") Then
  36.                 bad[ex] = 1
  37.                 resn :- 1
  38.                 Exit
  39.             EndIf
  40.             from = find
  41.         Next
  42.     Next
  43.    
  44.     Local ret$[resn]
  45.     Local n% = 0
  46.     For Local ex% = 0 To arr.Length-1
  47.         If bad[ex] Then Continue
  48.         Local e$ = arr[ex]
  49.         ret[n] = e
  50.         n :+ 1
  51.     Next
  52.    
  53.     Return ret
  54. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal