are two strings the same?
BlitzMax Forums/BlitzMax Beginners Area/are two strings the same?
| ||
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 |
| ||
string1:String="HELLO" string2:String="HELLO" If string1=string2 Print string1 + " World!" Else Print "Strings are not equal" EndIf |
| ||
*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) |
| ||
the strings both contain numbers, would this affect it in any way? cheers charlie |
| ||
Local String1:String = "1" Local String2:String = "1" If String1 = String2 Then Print "equals" |
| ||
no |
| ||
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 |
| ||
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 |
| ||
|
| ||
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). |
| ||
Sorry for double posting. and thanks Perturbatio, does this mean that numbers in strings are case sensitive? cheers charlie |
| ||
No, Trimming the string is removing the "next line" escape character. Numbers do not have "case". |
| ||
a better way of backspacing a string would be to do this:theString$ = Left(theString$, Len(theString$) - 1) |
| ||
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. |
| ||
ok, thanks very much cheers charlie |