Strings are usually given a set length. For example you may dimension a string as follows :
MyWord as STRING * 20
This will create a variable called MyWord and give it a length of 20 characters.
Consider this code :
MyWord as STRING * 20 MyWord = "Hello" SearchWord$ = "Hello" if MyWord = SearchWord$ then Print "They are the same" Else Print "They are different" End if
If you run this You will get "They are different" ... Why are they different ??
They are different becasue the two string variables are of different length
The command MyWord = "Hello" will result in the variable being stored as Hello############## where # represents NULL or empty characters.
Now is you compare MyWord with another string, for example :
SearchWord$ = "Hello", it wont work. This is because SeachWord$ is of a different length ...
There is two ways :
To compare MyWord with SearchWord$, you need to find the significant letters in the string. Here's how ...
First find out how long the string is ...
SearchLength = LEN(SearchWord$)
Next, find the left most letters in the string we are comparing this to ...
LEFT$(MyWord,SearchLength)
Top put it all together ....
MyWord as STRING * 20 MyWord = "Hello" SearchWord$ = "Hello" SearchLength = LEN(SearchWord$) if LEFT$(MyWord,SearchLength) = LEFT$(SearchWord$,SearchLength) then Print "They are the same" Else Print "They are different" End if
This will print ..."They are the same!!"
(Powered by PWP Version 1.4.2)