are two strings the same?

BlitzMax Forums/BlitzMax Beginners Area/are two strings the same?

jkrankie(Posted 2005) [#1]
this bit doesnt work, What am i doing wrong? I looked in the docs for a string.equals() function bu i cant find one.

if String1$=String2$

do something

end if

cheers
charlie


tonyg(Posted 2005) [#2]
string1:String="HELLO"
string2:String="HELLO"
If string1=string2
   Print string1 + " World!"
Else
   Print "Strings are not equal"
EndIf



Perturbatio(Posted 2005) [#3]
*EDIT*
code removed since I was beaten to it.

However, now would be a good time to point out that the equality test for strings is case sensitive.
(you could use ToLower() to ensure same case)


jkrankie(Posted 2005) [#4]
the strings both contain numbers, would this affect it in any way?

cheers
charlie


Perturbatio(Posted 2005) [#5]
Local String1:String = "1"
Local String2:String = "1"

If String1 = String2 Then Print "equals"



Diablo(Posted 2005) [#6]
no


jkrankie(Posted 2005) [#7]
i still cant get this to work in my code.

Graphics 1024,768,32,60 

	Local userTypedString:String
    Local regString:String
    Local lastCharacter:Int
    Local keycounter=0
    Local canenter=True
    userTypedString$=""
    lastCharacter = 0
    Local endfunc=False
    Local regnum[100]
    regString$=""
    
        While  endfunc=False
                

            SetScale 1,1
            DrawText "Silly test Registration",10,30
            DrawText "Type your name Exactly as in the Email!",10,60
            If canEnter=True
                If keyCounter<10
                    If Not lastCharacter = 0 Then
                        userTypedString$ = userTypedString$ + Chr(lastCharacter)        
                        regnum[keyCounter]=Asc(Chr(lastCharacter))
                        regString$=regString$+regnum[keyCounter]
                        keyCounter:+1
                    FlushKeys
                    EndIf
                End If
            End If
            
            
            DrawText "Hit return to confirm your name...",10,120
            
            SetScale 4,4
            DrawText userTypedString$, 10, 150       
            
            SetScale 1,1
            
            If KeyHit(key_backspace) And keycounter>=0
               userTypedString$=""
               regString$=""
               keycounter=0
               canenter=False
               FlushKeys
            Else
                lastCharacter = GetChar()
                canenter=True
            End If
    
            If KeyHit(key_return)
            	endfunc=True
            	FlushKeys
            	Exit
            End If
   
            Flip                    
            Cls                             
        
            
        Wend
        
       endfunc=False
       userTypedString$=Null
       keycounter=0
        While  endfunc=False
                

            SetScale 1,1
            DrawText "Silly test Registration",10,30
            DrawText "Type your Registration Exactly as in the Email!",10,60
           
		  If canEnter=True
                
                If keyCounter<100
                    If Not lastCharacter = 0 Then
                    
                    userTypedString$ = userTypedString$ + Chr(lastCharacter)        
                    
                    keyCounter:+1
                    FlushKeys
                    EndIf
                End If
            End If
            
            DrawText "Hit return to confirm your code...",10,120
            
            SetScale 1,1
            DrawText userTypedString$, 10, 150       
            
            SetScale 1,1
                        
            DrawText regString$,10,300
            
            If KeyHit(key_backspace) And keycounter>=0
               userTypedString$=Mid$(userTypedString$,0,keyCounter)
               keycounter=keycounter-1
               canenter=False
               FlushKeys
            Else
                lastCharacter = GetChar()
                canenter=True
            End If
    
            If KeyHit(key_return)
                endfunc=True
                FlushKeys
            End If
   
            Flip                    
            Cls                                    
            
        Wend
        
	   If userTypedString=regString           
			Print"same"
        Else
              Print"not the same"
        End If
        
       



I must be doing something wrong.

cheers
charlie


jkrankie(Posted 2005) [#8]
i still cant get this to work in my code.

Graphics 1024,768,32,60 

	Local userTypedString:String
    Local regString:String
    Local lastCharacter:Int
    Local keycounter=0
    Local canenter=True
    userTypedString$=""
    lastCharacter = 0
    Local endfunc=False
    Local regnum[100]
    regString$=""
    
        While  endfunc=False
                

            SetScale 1,1
            DrawText "Silly test Registration",10,30
            DrawText "Type your name Exactly as in the Email!",10,60
            If canEnter=True
                If keyCounter<10
                    If Not lastCharacter = 0 Then
                        userTypedString$ = userTypedString$ + Chr(lastCharacter)        
                        regnum[keyCounter]=Asc(Chr(lastCharacter))
                        regString$=regString$+regnum[keyCounter]
                        keyCounter:+1
                    FlushKeys
                    EndIf
                End If
            End If
            
            
            DrawText "Hit return to confirm your name...",10,120
            
            SetScale 4,4
            DrawText userTypedString$, 10, 150       
            
            SetScale 1,1
            
            If KeyHit(key_backspace) And keycounter>=0
               userTypedString$=""
               regString$=""
               keycounter=0
               canenter=False
               FlushKeys
            Else
                lastCharacter = GetChar()
                canenter=True
            End If
    
            If KeyHit(key_return)
            	endfunc=True
            	FlushKeys
            	Exit
            End If
   
            Flip                    
            Cls                             
        
            
        Wend
        
       endfunc=False
       userTypedString$=Null
       keycounter=0
        While  endfunc=False
                

            SetScale 1,1
            DrawText "Silly test Registration",10,30
            DrawText "Type your Registration Exactly as in the Email!",10,60
           
		  If canEnter=True
                
                If keyCounter<100
                    If Not lastCharacter = 0 Then
                    
                    userTypedString$ = userTypedString$ + Chr(lastCharacter)        
                    
                    keyCounter:+1
                    FlushKeys
                    EndIf
                End If
            End If
            
            DrawText "Hit return to confirm your code...",10,120
            
            SetScale 1,1
            DrawText userTypedString$, 10, 150       
            
            SetScale 1,1
                        
            DrawText regString$,10,300
            
            If KeyHit(key_backspace) And keycounter>=0
               userTypedString$=Mid$(userTypedString$,0,keyCounter)
               keycounter=keycounter-1
               canenter=False
               FlushKeys
            Else
                lastCharacter = GetChar()
                canenter=True
            End If
    
            If KeyHit(key_return)
                endfunc=True
                FlushKeys
            End If
   
            Flip                    
            Cls                                    
            
        Wend
        
	   If userTypedString=regString           
			Print"same"
        Else
              Print"not the same"
        End If
        
       



I must be doing something wrong.

cheers
charlie


Perturbatio(Posted 2005) [#9]



taxlerendiosk(Posted 2005) [#10]
It looks like hitting return from the previous entry is being added on as ASCII character 13 on the front of the code entry string (use Asc on userTypedString to find this out).


jkrankie(Posted 2005) [#11]
Sorry for double posting.

and thanks Perturbatio, does this mean that numbers in strings are case sensitive?

cheers
charlie


taxlerendiosk(Posted 2005) [#12]
No, Trimming the string is removing the "next line" escape character. Numbers do not have "case".


Diablo(Posted 2005) [#13]
a better way of backspacing a string would be to do this:
theString$ = Left(theString$, Len(theString$) - 1)



Perturbatio(Posted 2005) [#14]
and thanks Perturbatio, does this mean that numbers in strings are case sensitive?


sorry, I should have removed the ToLower() part, but I was just hacking away.


jkrankie(Posted 2005) [#15]
ok, thanks very much

cheers
charlie