March 05, 2021, 07:05:14 AM
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email
?
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Like stats
Home
Forum
Help
Search
Gallery
Login
Register
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
Algorithms
»
[bmx] Search String Array by N [ 1+ years ago ]
« previous
next »
Print
Pages: [
1
]
Go Down
Author
Topic: [bmx] Search String Array by N [ 1+ years ago ] (Read 477 times)
BlitzBot
Jr. Member
Posts: 1
Total likes: 0
[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
Function
SearchStrings$
[
]
(
search$, arr$
[
]
)
Local
clean$ =
""
Local
l$ =
""
For
Local
ex% =
0
To
search.Length-
1
Local
p$ =
Chr
(
search
[
ex
]
)
If
p =
"*"
And
l =
"*"
Then
Continue
If
p =
"*"
Then
p =
"|*|"
clean :+ p
Next
Local
s$
[
]
= SplitString
(
clean,
"|"
)
Local
resn%=arr.Length
Local
bad%
[
arr.Length
]
memset_
(
bad,
0
,arr.Length*
4
)
For
Local
ex% =
0
To
arr.Length-
1
Local
e$ = arr
[
ex
]
If
e =
""
Or
e =
Null
Then
bad
[
ex
]
=
1
resn :-
1
Continue
EndIf
Local
from% =
0
, find% =
0
For
Local
i% =
0
To
s.Length-
1
Local
p$ = s
[
i
]
If
p =
"*"
And
i = s.Length-
1
Then
Continue
ElseIf
p =
"*"
Then
p = s
[
i+
1
]
EndIf
find = e.Find
(
p,from
)
If
find = -
1
Or
(
find >
0
And
i =
0
And
s
[
i
]
<>
"*"
)
Then
bad
[
ex
]
=
1
resn :-
1
Exit
EndIf
from = find
Next
Next
Local
ret$
[
resn
]
Local
n% =
0
For
Local
ex% =
0
To
arr.Length-
1
If
bad
[
ex
]
Then
Continue
Local
e$ = arr
[
ex
]
ret
[
n
]
= e
n :+
1
Next
Return
ret
End
Function
Comments :
none...
Logged
Print
Pages: [
1
]
Go Up
« previous
next »
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
Algorithms
»
[bmx] Search String Array by N [ 1+ years ago ]
SimplePortal 2.3.6 © 2008-2014, SimplePortal