-
Oct 17th, 2021, 09:40 PM
#1
Thread Starter
Frenzied Member
Like Operator
I have a variable z= "1. " = which is any number full stop and space.
Then If z Like "[1-9]*. " then....
Sometimes there's a leading Alpha char e.g z = "C1. "
I expected If z Like "[A-Z][1-9]*. " then.... to work, but it doesn't.
This should be as fast as possible without too many IFs or evaluations.
What might be a good solution?
Thanks.
-
Oct 18th, 2021, 02:54 AM
#2
Re: Like Operator
The Like-Operator is not RegEx.
out of my left sleeve:
I take it you mean digit (not number) --> What about a "0"?
If it's actually digit, then you look for Length = 3 (1 Digit + 1 period + 1 Space)
If Len(z)=4 Then z=Mid$(z, 2) 'Has leading Alpha
If Len(z)=3 Then 'Sanity-Check
'DoWhatever
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Oct 18th, 2021, 03:09 AM
#3
Thread Starter
Frenzied Member
Re: Like Operator
Thanks for that, didn't think to check for Len.
Yes it could be "C10."
-
Oct 18th, 2021, 03:14 AM
#4
Re: Like Operator
You can stack multiple LIKE checks like this
If z Like "[0-9]*. " Then
'--- do something ElseIf z Like "[A-Z][0-9]*. " Then
'--- do the same ElseIf z Like "..." Then
'--- do the same Else
'--- fail End If
cheers,
</wqw>
-
Oct 18th, 2021, 03:44 AM
#5
Re: Like Operator
Originally Posted by AlexanderBB
Thanks for that, didn't think to check for Len.
Yes it could be "C10."
then your If z Like "[1-9]*. " is not going to find that.....
EDIT: Forget what i said..... it's too early in the morning.....
In case it's actually a number, sometimes preceeded by an alpha, i revert to my favourite API-Combo of StrSpn/StrCSpn
Out of curiosity: Is your current check a simple boolean evaluation, or do you need the number for some processing?
Last edited by Zvoni; Oct 18th, 2021 at 03:52 AM.
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Oct 18th, 2021, 08:27 AM
#6
Lively Member
Re: Like Operator
another possibility is
Code:
If z Like "*#*.?" Or z Like "*##. " Then
* = match zero or more char
# = match a single digit
? = match single char
other very general expressions that should work could be
Code:
If z Like "*#*.?" Then
Code:
If z Like "*[0-9]*.?" Then
Code:
If z Like "*[0-9]??" Then
Code:
If z Like "*#*?" Then
-
Oct 18th, 2021, 04:55 PM
#7
Thread Starter
Frenzied Member
Re: Like Operator
Zvoni I'm doing quite a bit with the result. There is a 3rd condition. This seems to be working
If (Track Like "[1-9]. *") Or (Track Like "[A-Z][1-9]*. ") Then
ElseIf Track Like "*)" Then
End If
I'm still testing (may need the '0'). I found the space helped with false positives.
Was hoping to avoid "Or" thinking it might be faster without it.
Going to try Len next.
-
Oct 19th, 2021, 01:01 AM
#8
Re: Like Operator
Well, if you show how some "real" values for z look like, and what you want to do with it, we might come up with a different solution
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|