All BASIC

BASIC Developer & Support Resources => Scripting Languages => Topic started by: John on April 13, 2015, 07:07:11 PM

Title: Script BASIC Case Sensitivity
Post by: John on April 13, 2015, 07:07:11 PM
The BP.org (http://forum.basicprogramming.org/index.php/topic,3968.0.html) forum has a thread going about INSTR case sensitivity. Script BASIC takes a more global approach with syntax that uses compares. The SB compare OPTION can be turned ON/OFF as many times as you wish during the execution of your program.

Code: Script BASIC
  1. ' Case Sensitivity in Script BASIC
  2.  
  3. a_uc = "A"
  4. a_lc = "a"
  5. a_mix = "aBc"
  6.  
  7. PRINT INSTR(a_mix,"b"),"\n"
  8.  
  9. ' Enable SB case insensitive option
  10.  
  11. OPTION COMPARE sbCaseInsensitive
  12.  
  13. PRINT INSTR(a_mix,"b"),"\n"
  14.  
  15. IF a_uc = a_lc THEN PRINT "Is case insensitive equal\n"
  16.  
  17. PRINT REPLACE(a_mix, "b", "*"),"\n"
  18.  
  19. OPTION COMPARE sbCaseSensitive
  20.  
  21. PRINT INSTR(a_mix,"b"),"\n"
  22.  

Output


jrs@laptop:~/sb/sb22/test$ scriba case.sb
undef
2
Is case insensitive equal
a*c
undef
jrs@laptop:~/sb/sb22/test$

Title: Re: Script BASIC Case Sensitivity
Post by: Mike Lobanovsky on April 13, 2015, 09:23:05 PM
Hi John,

FBSL functions Instr(), InstrRev() and Tally() are case-sensitive on default but have a trailing optional case sensitivity argument (Boolean TRUE/FALSE) that can be used to precise the desired comparison mode.

Arithmetic comparison of strings with a single equality conditional = is however always case sensitive.

FBSL features yet another, double equality, conditional == that compares FBSL objects based on not only their actual value, but also their data type. So, if one object is a dynamic string and the other is a fixed length string, double equality comparison will always return FALSE even when the actual characters stored in the two strings are equal.
Title: Re: Script BASIC Case Sensitivity
Post by: John on April 13, 2015, 09:37:53 PM
Thanks Mike for the explanation how case sensitivity works in FBSL.

I would be happy to add FBSL syntax highlighting here on All BASIC if you can send me a GeSHi file for it.

Title: Re: Script BASIC Case Sensitivity
Post by: John on April 15, 2015, 12:12:06 AM
Quote from: Paul Dunn - BP.org (http://forum.basicprogramming.org/index.php/topic,3968.msg29302.html#msg29302)
Yes, POS is SpecBAS's INSTR, but it's case-sensitive. I'm thinking that I could add a case insensitivity flag, but it would likely be a bit different to implementations here... Of course, you could just do

Code: [Select]
LET p=POS(LOW$ substr$,LOW$ host$)

Which would do the same thing.

D.

I gave Paul's suggestion a try rather than using the SB case sensitivity OPTION and the only side effect was with REPLACE. (changes reference string to lower case)

Code: Script BASIC
  1. ' Case Sensitivity in Script BASIC
  2.  
  3. a_uc = "A"
  4. a_lc = "a"
  5. a_mix = "aBc"
  6.  
  7. PRINT INSTR(a_mix,"b"),"\n"
  8.  
  9. ' Enable SB case insensitive option
  10.  
  11. ' OPTION COMPARE sbCaseInsensitive
  12.  
  13. PRINT INSTR(LCASE(a_mix),"b"),"\n"
  14.  
  15. IF LCASE(a_uc) = a_lc THEN PRINT "Is case insensitive equal\n"
  16.  
  17. PRINT REPLACE(LCASE(a_mix), "b", "*"),"\n"
  18.  
  19. ' OPTION COMPARE sbCaseSensitive
  20.  
  21. PRINT INSTR(a_mix,"b"),"\n"
  22.  

Output


jrs@laptop:~/sb/sb22/test$ scriba lcase.sb
undef
2
Is case insensitive equal
a*c
2
jrs@laptop:~/sb/sb22/test$