Match varialbes with case sensitivity.

The place to discuss anything and everything about running your LiveCode on Android

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Googie85
Posts: 226
Joined: Tue Aug 05, 2014 10:07 am

Match varialbes with case sensitivity.

Post by Googie85 » Fri Jan 31, 2025 5:13 am

Hii Guys!!

I'm wondering how to match 2 variables with case sensitivity. For example, AlPhA123 will currently match Alpha123. How do I match these variables with Case Sensitivity?

Many Thanks,

Googie.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10080
Joined: Fri Feb 19, 2010 10:17 am

Re: Match varialbes with case sensitivity.

Post by richmond62 » Fri Jan 31, 2025 8:05 am

Use caseSensitive.

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Match varialbes with case sensitivity.

Post by Klaus » Fri Jan 31, 2025 9:57 am

From the docs:
Important: Messages, object names, and LiveCode terms are never treated as case-sensitive,
even if the caseSensitive is set to true.

That also applies to variables.

Add a number to your variables to avoid these doublettes!

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10080
Joined: Fri Feb 19, 2010 10:17 am

Re: Match varialbes with case sensitivity.

Post by richmond62 » Fri Jan 31, 2025 10:17 am

That also applies to variables.

Add a number to your variables to avoid these doublettes!
Aye, well: and what happens if the OP CANNOT differentiate the variables in the way you suggest?

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10080
Joined: Fri Feb 19, 2010 10:17 am

Re: Match varialbes with case sensitivity.

Post by richmond62 » Fri Jan 31, 2025 10:31 am

Just stick your variables into 2 fields:
-
Screenshot 2025-01-31 at 11.28.15.png
-
Button 'SENSITIVE':

Code: Select all

on mouseUp
   set the caseSensitive to true
   if fld "f1" contains fld "f2" then
      put "MATCH" into fld "f3"
   else
      put "NOPE" into fld "f3"
   end if
end mouseUp
And, for once, Klaus, you'll see that fields DO have their uses. 8)
Attachments
Insensitivity.livecode.zip
Stack.
(1.12 KiB) Downloaded 394 times

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Match varialbes with case sensitivity.

Post by Klaus » Fri Jan 31, 2025 11:05 am

Code: Select all

And, for once, Klaus, you'll see that fields DO have their uses.  8)
Yes, but this completely OFF-topic here and does not solve the problem! :-D
Aye, well: and what happens if the OP CANNOT differentiate the variables in the way you suggest?
How is that in english? First come, first serve?
Means that LC will treat these as the SAME variable so it will get overwritten whenever the TS accesses them.

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Match varialbes with case sensitivity.

Post by Klaus » Fri Jan 31, 2025 11:06 am

This:

Code: Select all

 on mouseUp
   set the casesensitive to TRUE
   put 1 into taaa
   put 2 into tAAA
   put taaa && tAAA
end mouseUp
will give you: 2 2 in the messagebox as exspected.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10080
Joined: Fri Feb 19, 2010 10:17 am

Re: Match varialbes with case sensitivity.

Post by richmond62 » Fri Jan 31, 2025 11:09 am

does not solve the problem!
The 'problem' as far as I can see is that the OP wants to compare 2 variables and differentiate them on the basis of whether , while being alphabetically the same, there is a CASE difference in those alphabetic characters.

By putting the 2 variables into 2 fields they CAN be compared in that way.

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Match varialbes with case sensitivity.

Post by Klaus » Fri Jan 31, 2025 11:32 am

Yes, sure, but if that is the case (using two FIELDS to compare two variable names, which would make
the execution of a script a TAD longer than neccessary), then something is going completely wrong with the scripting! 8)

And even that will make LC NOT differ between the variables in the scripts.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10080
Joined: Fri Feb 19, 2010 10:17 am

Re: Match varialbes with case sensitivity.

Post by richmond62 » Fri Jan 31, 2025 2:20 pm

OK: go for this:
-
SShot 2025-01-31 at 15.18.25.png
-

Code: Select all

on mouseUp
   put empty into fld "f3"
   put fld "f1" into EFF1
   put EFF1 into EFF1x
   put fld "f2" into EFF2
   put EFF2 into EFF2x
   repeat until EFF1x is empty
      put codePointToNum(char 1 of EFF1x) after EFF1z
      delete char 1 of EFF1x
   end repeat
   repeat until EFF2x is empty
      put codePointToNum(char 1 of EFF2x) after EFF2z
      delete char 1 of EFF2x
   end repeat
   if EFF1z = EFF2z then
      put "MATCH" into fld "f3"
   else
      put "NOPE" into fld "f3"
   end if
end mouseUp
No fields were hurt during the making of this stack. 8)
Attachments
Two Birds.livecode.zip
Stack.
(1.14 KiB) Downloaded 399 times

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Match varialbes with case sensitivity.

Post by Klaus » Fri Jan 31, 2025 2:25 pm

No fields were hurt during the making of this stack.
However they were USED!
Otherwise LC cannot differ between these two poorly chosen variable names!
So it seems there is no script-only way to do so.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10080
Joined: Fri Feb 19, 2010 10:17 am

Re: Match varialbes with case sensitivity.

Post by richmond62 » Fri Jan 31, 2025 2:40 pm

two poorly chosen variable names!
Aesthetics were not my first thought; functionality was. 8)

And, I thought 'EFF1' and 'EFF2' were better than 'EFFon' and 'EFFoff'. :D

Code: Select all

no script-only way
Err: that's what I just did:

Code: Select all

if EFF1z = EFF2z then
--- EFF1 and EFF2 match
end if

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Match varialbes with case sensitivity.

Post by dunbarx » Fri Jan 31, 2025 2:59 pm

Re-form the variables into a string of their ASCII characters. Here is a long-winded demo script using a button and a field. Put this in the button script:

Code: Select all

on mouseUp
   get "dog"
   repeat for each char tChar in it
      put charToNum(tChar) after temp
   end repeat
   put temp into fld 1
   
     get "DoG"
     repeat for each char tChar in it
      put charToNum(tChar) after temp1
   end repeat
   put temp1 into line 2 of  fld 1
end mouseUp
Craig
Last edited by dunbarx on Fri Jan 31, 2025 3:05 pm, edited 1 time in total.

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Match varialbes with case sensitivity.

Post by Klaus » Fri Jan 31, 2025 3:03 pm

richmond62 wrote:
Fri Jan 31, 2025 2:40 pm
two poorly chosen variable names!
Aesthetics were not my first thought; functionality was. 8)
...
I meant Googies variable names: AlPhA123 and Alpha123

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Match varialbes with case sensitivity.

Post by dunbarx » Fri Jan 31, 2025 3:07 pm

Google85

How do you want to use this ability? My demo script can tell the difference between "dog" and "DoG", but then what?

Craig

Post Reply