Page 2 of 2

Re: an equal '=' test string not case sensitive

Posted: Sat Jul 27, 2013 7:52 pm
by davido
HI TI-994A,

Thank you for your comments. :D

I missed the finer point. :oops:

Re: an equal '=' test string not case sensitive

Posted: Sat Jul 27, 2013 7:52 pm
by skywalk

Code: Select all

CompilerIf #PB_Compiler_Debugger:CompilerError "Turn OFF debugger for Speed Tests!":CompilerEndIf
s1$ = "hello!": #s = "HELLO!": s2$ = #s
Macro StrCmp(str1, str2, UseCase=#PB_String_NoCase)
  Bool(CompareMemoryString(@str1, @str2, UseCase) = #PB_String_Equal)
EndMacro
Macro StrCmpLC(str1, str2, UseCase=#PB_String_NoCase)
  Bool(LCase(str1) = LCase(str2))
EndMacro
Procedure StrCmpP(a$, b$)
  ProcedureReturn Bool(CompareMemoryString(@a$, @b$, #PB_String_NoCase) = #PB_String_Equal)
EndProcedure
nTries = 1e6
t = ElapsedMilliseconds()
For L = 1 To nTries
  StrCmp(s1$, s2$)
Next
MessageRequester("Fastest", "CompareMemoryString using string variable -> " + Str(ElapsedMilliseconds() - t) + "ms")
t = ElapsedMilliseconds()
For L = 1 To nTries
  StrCmpLC(s1$, #s)
Next
MessageRequester("Slower", "LCase() = LCase() -> " + Str(ElapsedMilliseconds() - t) + "ms")
t = ElapsedMilliseconds()
For L = 1 To nTries
  StrCmpP(s1$, #s)
Next
MessageRequester("Slowest", "Procedure+CompareMemoryString enabling use of string #const -> " + Str(ElapsedMilliseconds() - t) + "ms")

Re: an equal '=' test string not case sensitive

Posted: Wed Nov 16, 2022 12:56 am
by idle
simple and full case folding string cmp
viewtopic.php?t=80275
https://dnscope.io/idlefiles/casefold.pb

Re: an equal '=' test string not case sensitive

Posted: Wed Nov 16, 2022 9:51 am
by BarryG
TI-994A wrote: Wed Jul 24, 2013 3:18 amperhaps you could make use of PureBasic's FindString() function with the #PB_String_NoCase flag
Nope. I modified your example to show why:

Code: Select all

s1$ = "hello said! - but this is different"
s2$ = "HELLO Said!"
If FindString(s1$, s2$, 1, #PB_String_NoCase)
  result$ = "The two strings match!" ; This will be the result. :)
Else
  result$ = "The two strings don't match."
EndIf
MessageRequester("Case Insensitive String Compare", result$)

Re: an equal '=' test string not case sensitive

Posted: Wed Nov 16, 2022 11:02 am
by idle
What are you on about Barry? Answer this.
idle wrote: Wed Nov 16, 2022 12:56 am simple and full case folding string cmp
viewtopic.php?t=80128
https://dnscope.io/idlefiles/casefold.pb

Re: an equal '=' test string not case sensitive

Posted: Wed Nov 16, 2022 11:34 am
by BarryG
I was replying to TI-994A's code, and showed why it doesn't work. He said to try using FindString() to match strings, and I showed why it can fail (it returns a match when it shouldn't, because s1$ and s2$ are different).

Re: an equal '=' test string not case sensitive

Posted: Wed Nov 16, 2022 6:23 pm
by Mijikai
Another way (Windows only):

Code: Select all

EnableExplicit

Import ""
  _wcsicmp.i(*str1,*str2)
EndImport

Macro CompareString(_str1_,_str2_)
  Bool(_wcsicmp(_str1_,_str2_) = 0)  
EndMacro

Global s1.s = "Hello World!"
Global s2.s = "HELLO WORLD!"

Debug CompareString(s1,s2)
Debug CompareString(@s1,@s2)

s2 = ":)"

Debug CompareString(s1,s2)
Debug CompareString(@s1,@s2)

Debug CompareString(":)",s2)

End

Re: an equal '=' test string not case sensitive

Posted: Wed Nov 16, 2022 7:14 pm
by Caronte3D
I get: "Unresolved external" error

Re: an equal '=' test string not case sensitive

Posted: Wed Nov 16, 2022 7:42 pm
by Mijikai
I used PB 6.00 x64 - the function is part of the crt lib.
Unless i updated it manually it should work out of the box.

Re: an equal '=' test string not case sensitive

Posted: Wed Nov 16, 2022 7:44 pm
by idle
You have just answered a post from 2013 without looking at the solution I posted to this old topic. It provides a complete solution to the problem.
idle wrote: Wed Nov 16, 2022 12:56 am simple and full case folding string cmp
viewtopic.php?t=80128
https://dnscope.io/idlefiles/casefold.pb

Re: an equal '=' test string not case sensitive

Posted: Wed Nov 16, 2022 10:33 pm
by Caronte3D
Mijikai wrote: Wed Nov 16, 2022 7:42 pm I used PB 6.00 x64 - the function is part of the crt lib.
Unless i updated it manually it should work out of the box.
Ok, then doesn't work on x86 :wink:

Re: an equal '=' test string not case sensitive

Posted: Thu Nov 17, 2022 8:26 am
by BarryG
idle wrote: Wed Nov 16, 2022 7:44 pmYou have just answered a post from 2013
Oh, I didn't realise that. I saw your post (which resurrected the thread) and therefore mistakenly thought this was a current topic, including the post that I replied to. I don't check the dates of posts before replying because my board prefs are set to only show me new posts since my last visit.

My comment is still valid regardless though, as an explanation to newbies of why TI-994A's approach won't work.

Re: an equal '=' test string not case sensitive

Posted: Thu Nov 17, 2022 8:53 am
by idle
BarryG wrote: Thu Nov 17, 2022 8:26 am
idle wrote: Wed Nov 16, 2022 7:44 pmYou have just answered a post from 2013
Oh, I didn't realise that. I saw your post (which resurrected the thread) and therefore mistakenly thought this was a current topic, including the post that I replied to. I don't check the dates of posts before replying because my board prefs are set to only show me new posts since my last visit.

My comment is still valid regardless though, as a demonstration of why TI-994A's approach won't work.
Thanks, I was just trying to link the topic for search purposes and then got exasperated by all the replies.
I have the emotional intelligence of John macenroe https://youtu.be/fd90m3xKfl8

Re: an equal '=' test string not case sensitive

Posted: Thu Nov 17, 2022 8:55 am
by BarryG
It's all good, mate.