String operators

Strings are collection of alphanumeric characters. These can also be called text. Operators which act upon Strings are very different than with numbers. For example -

a = "hello" + " bert";
b = "goodbye" - "bert";

a will become "hello bert" while b will cause a syntax error. This is because - is ambigious when it comes to strings. how can you subtract words? The same goes for the other mathimatical operators.

Conditional operators also have different meanings. Have a test! Look at the following conditions, which ones are true and which ones are false-

"Z" < "a"
"bert" = "BERT"
"adam" < "alice"

"Z" < "a" is true. Capital letters are seperate to lower case. It uses the ASCII table to determine what values are bigger or smaller. ASCII for upper case Z is 90 and ASCII for lower case a is 97. 90 is less than 97 so Z IS less than a.

"bert" = "BERT" is false. Lower case and uppercase are treated seperatly. Again this is due to their ASCII values. If equality needs to be tested on strings you should always convert them to lower case (or upper case!) that way you are comparing like for like.

"adam" < "alice" is true. It does a letter by letter comparison. If the first two letters are equal then it will compare the next 2 letters and so on. In this case d is less than l so "adam" is less than "alice". If you look at the ASCII for both of these it makes more sense. a is 97, d is 100 and l is 108. 100 is less than 108.

As well as the normal boolean logical operators Strings have some special operators which you need to be aware of. These are covered in the next section

next LEFT and RIGHT >>