Logical NOT when comparing strings

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
John R. Sowden
User
User
Posts: 19
Joined: Sat May 10, 2014 2:58 am
Location: San Rafael, CA USA

Logical NOT when comparing strings

Post by John R. Sowden »

I guess I have been too spoiled in Foxpro 2.6/DOS. I use the not operator in string comparison all the time, e.g.:

while not choice$ $ "ABCDEFQ"
input routing
wend
(use the input data)

This seems to be so basic for a language, that I spent a lot of time searching for the answer, in case different words were used to describe it.

this also uses the logical substring search, but I will put that in another message so it can be addressed separately.

John
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Logical NOT when comparing strings

Post by IdeasVacuum »

Hi John

I do not understand your snippet, but you can indeed use Not:

Code: Select all

While Not UCase(choice$) = "ABCDEFQ"
input choice$
Wend
;Don't try this at home
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
John R. Sowden
User
User
Posts: 19
Joined: Sat May 10, 2014 2:58 am
Location: San Rafael, CA USA

Re: Logical NOT when comparing strings

Post by John R. Sowden »

I'm a little lost. ucase converts lower case to upper case. I want to compare strings. The docs say that the NOT function does not work with strings.

John
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Logical NOT when comparing strings

Post by Demivec »

Would something like this work for you?

Code: Select all

Macro NotIn(variable, content = "")
 Bool(Not FindString(content, variable))
EndMacro

OpenConsole()

Print("Select a choice (ABCDEFQ)?") ;prompt
While NotIn(choice$, "ABCDEFQ")
  ;input routing
  choice$ = Input() ;need to press enter after each input for this method
 Print("...") ;simple display to show we are whistling while we wait;)
Wend
;(use the input Data)
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Re: Logical NOT when comparing strings

Post by Mistrel »

We USED to have this behavior but it was removed in PureBasic 5.0. It was one of my favorite features and I used it everywhere..

http://www.purebasic.fr/english/viewtop ... 13&t=57715
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Logical NOT when comparing strings

Post by IdeasVacuum »

Hi John

I introduced UCase so that in the string comparison it would be like-for-like. I'm sorry I did not know that NOT had been removed from string operations - that is a great pity, it seems logical to use it (pun intended).
You can do it like this (tested!):

Code: Select all

OpenConsole() ;To enable use of Input()
     PrintN("Enter a String")

While UCase(choice$) <> "ABCDEFQ"
            choice$ = Input()
Wend
....but do you really want a Console program rather than a nice shiny Window?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Logical NOT when comparing strings

Post by Dude »

User avatar
Lord
Addict
Addict
Posts: 900
Joined: Tue May 26, 2009 2:11 pm

Re: Logical NOT when comparing strings

Post by Lord »

If you really want to use "NOT", use it like this:

Code: Select all

OpenConsole() ;To enable use of Input()
     PrintN("Enter a String")

While Not Bool(UCase(choice$) = "ABCDEFQ")
            choice$ = Input()
Wend
But as IdeasVacuum already stated it (still) works like this:

Code: Select all

OpenConsole() ;To enable use of Input()
     PrintN("Enter a String")

While Not UCase(choice$) = "ABCDEFQ"
            choice$ = Input()
Wend
Image
Post Reply