Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16

Thread: Idea for case-insensitive string comparisons

  1. #11
    I am not sure but i think that this native win32 api function compare string in not case sensitive way..
    Declare Function strcmp Lib "kernel32" Alias "lstrcmpA" (ByVal psz1 As 
     String, ByVal psz2 As String) As Long
    

  2. #12
    thinBasic MVPs
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Rep Power
    159
    Why not just create a unit file with the commands you require, here is an example

    Dim s As StringDim ss As String
    Dim sMsg As String
    
    s= "T"
    ss="T"
    
    If eq(s,ss) Then 
      sMsg += "The strings are equal"
    Else
      sMsg += "The strings are not equal"
    End If
    
    Function eq(ByRef string1 As String, ByRef string2 As String)
      If Ucase$(String1) = Ucase$(String2) Then 
        Return %TRUE
      Else
        Return %FALSE
      End If
    End Function
    
    Function neq(ByRef string1 As String, ByRef string2 As String)
      If Ucase$(String1) = Ucase$(String2) Then 
        Return %FALSE
      Else
        Return %TRUE
      End If
    End Function
    
    Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
    Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
    Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
    Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370

  3. #13
    Quote Originally Posted by zlatkoAB View Post
    I am not sure but i think that this native win32 api function compare string in not case sensitive way..
    Declare Function strcmp Lib "kernel32" Alias "lstrcmpA" (ByVal psz1 As 
     String, ByVal psz2 As String) As Long
    
    You are probably thinking of lstrcmpiA. However, both routines handle C-style null-terminated strings, not Basic strings which have a byte count. There are "n" versions like lstrncmpiA that do a byte-counted case-insensitive compare, BUT you'd somehow have to get the lengths of both strings, and somehow pass that as a parameter to the compare routine. And again, even if this would work, it would mean having to write something like,

    IF lstrncmpiA(ONE,TWO,LEN(ONE)) = 0 THEN ...
    
    ' and that really isn't much better than
    
    IF UCASE$(ONE) = UCASE$(TWO) THEN ...
    
    ' that's why I am still holding out for ...
    
    IF ONE =: TWO THEN ...
    

  4. #14
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,529
    Rep Power
    170
    So I made a suggest which would probably not have come to my mind without this discussion - it's not exactly the way you wanted but the improvement of existing methods (see above) because I think they could really be useful if one had to compare text-content wherever in memory it might be located - even if the functionality is already available for one who uses those gray cells inside that bubble on top of the neck
    I think there are missing some Forum-sections as beta-testing and support

  5. #15
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    Quote Originally Posted by quatras9 View Post
    You are probably thinking of lstrcmpiA. However, both routines handle C-style null-terminated strings, not Basic strings which have a byte count.
    All thinBasic dynamic strings are BSTR string (OLE32 strings).
    BSTR strings are NULL terminated automatically by OLE32 engine.
    Ending NULL char does not count as string len but is just added by OLE32 engine just for compatibility reasons with ASCIIZ strings.
    Of course, because BSTR strings can have any NULL inside a dynamic strings, when passes to ASCIIZ strings the first NULL will count.


    Calling external functions requiring ASCIIZ strings can be done very easily: just declare parameters as ASCIIZ and thinBasic will take care of necessary conversions.

    The following is an example:
    Uses "console"
    
    
    Declare Function Are_String_Equal_Regardless_Case Lib "kernel32" Alias "lstrcmpi" (ByVal psz1 As Asciiz, ByVal psz2 As Asciiz) As Long
    
    
    String sOne = "this is a string"
    String sTwo = "THIS IS A STRING"
    
    
    PrintL Are_String_Equal_Regardless_Case (sOne, sTwo)
    WaitKey
    
    Reference of lstrcmpi function: http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx


    What about == as case insensitive string comparison?
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  6. #16
    Quote Originally Posted by John Spikowski View Post
    It might work if the thinBasic user has never experienced any other language before. I have alway known == to be a compare rather than an assignment. Why not put in the extra effort and follow the traditional BASIC standard like the SB examples I posted?
    Pretty much everyone has written in something else, so we always carry with us our "pet favorites" as far as preferred syntax.

    The == comes from C (and from there, it went to so many other places: C++, Java, Perl, etc.) as a straight comparison.
    In Rexx, == means "exactly equal" and so is not only case-sensitive but must be the exact length (it wont' ignore padding) and thus it's even "more" sensitive than the garden variety = compare.

    For Rexx, they have a whole second set of comparsions, so there is ==, <<, >>, <<=, >>= and /==, where /= is their not-equal. (They have a hard time deciding what not-equal should be, so there are many alternatives like \= and ¬=, etc.) TB's not-equal would be a problem, since it's <>. The only thing I could think of for <> to follow the pattern of = becoming == is <<>> which looks pretty weird. That's one reason why I like =: so much; it's not only easy to type and read, but it's consistent, with every comparison ending in the : colon.

    When you have a language that already makes heavy use of punctuation, trying to add new tokens that can be successfully recognized by the lexical scanner, AND be somehow meaningful, AND not be 'ugly', is really hard. The more mature the language is, the fewer "escape hatches" and "undeveloped property" is still left. You might have all kinds of cool ideas, but you start running out of places to "show-horn" them in to the language. You have to be extremely careful not to break the parser adding new, novel syntax.

    As far as "Why not put in the extra effort and follow the traditional BASIC standard", yes, one can simply write code like,

    IF UCASE$(ONE) = UCASE$(TWO) THEN ...

    and that IS standard BASIC. It never was a question of whether BASIC can DO it, only whether there could be a way to do it while at the same time writing less code. Personally, I like novel syntax, and I wouldn't be bothered at all by,

    IF ONE =: TWO THEN ...

    but a lot of people are bothered by changes to the language when they seem overly "radical". Of course, one man's 'radical' is another man's "cool". Depends on your point of view.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. String-in-String-Pointers?
    By ReneMiner in forum thinBasic General
    Replies: 9
    Last Post: 11-06-2013, 14:55
  2. Mixed Case Formatter
    By kryton9 in forum User tools
    Replies: 5
    Last Post: 04-06-2008, 00:28
  3. gamepad test comparisons
    By kryton9 in forum TBDI module. thinBasic Direct Input integration by MikeHart
    Replies: 18
    Last Post: 08-05-2007, 01:55

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •