String comparisations

Discussion of Inner Space

Moderators: Lavish Software Team, Moderators

Post Reply
Aanya
GamingTools Subscriber
Posts: 18
Joined: Thu Jan 27, 2005 5:15 am

String comparisations

Post by Aanya » Wed Feb 09, 2005 1:50 pm

Is there a way to compare strings in scripts ? I see a bunch of math operators but if i try to use any of them to compare 2 strings i get a syntax error in the script.

Lax
Owner
Posts: 6634
Joined: Fri Jun 18, 2004 6:08 pm

Post by Lax » Wed Feb 09, 2005 2:27 pm

IS math operators can only be used on numbers. String comparisons are done via members of the string data type, which information is not currently filled in on in the manual.

However, the basic datatypes work the same as MacroQuest 2's, and here's the necessary information:

Code: Select all

string
- Members:
...int Find[text]: Looks for the given text, gives position (currently NULL if not found)
...int Length: The length of the string
...string Upper: The string in all UPPER CASE
...string Lower: The string in all lower case
...string Left[length]: The left (length) of the string.. Left[2] of "Left" will be "Le"
...string Right[length]: The right (length) of the string.. Right[2] of "Left" will be "ft"
...string Left[-length]: The left ("all but" length) of the string.. Left[-1] of "Left" will be "Lef"
...string Right[-length]: The right ("all but" length) of the string.. Right[-1] of "Left" will be "eft"
...string Mid[position,length]: The left (length) starting at (position).. Mid[2,2] of "Left" will be "ef"
...int Compare[text]: -1 if the string is alphabetically before text, 0 if equal, 1 if after. Case does not count.
...int CompareCS[text]: -1 if the string is alphabetically before text, 0 if equal, 1 if after. Case counts.
...bool Equal[text]: Strings equal? Case does not count...
...bool NotEqual[text]: Strings not equal? Case does not count...
...bool EqualCS[text]: Strings equal? Case counts!
...bool NotEqualCS[text]: Strings not equal? Case counts!
...string Token[n,separator]: Retrieve a token from the string using a custom separator. Unlike Arg, this will not skip empty values
...int Count[char]: Count the number of occurrences of a particular character in the string
Equal, NotEqual, EqualCS, and NotEqualCS are what you will generally use. Compare and CompareCS are used like strcmp and stricmp (also known as strcasecmp) -- giving a result of -1, 0, or 1 depending on if it comes before, in the same position as, or after the comparison string. CS is short for Case Sensitive, which implies that the ones without CS are not case sensitive.

Be aware that Mid and Token are not currently implemented, and Token may actually be removed.

If working with text or with types that are not strings, you can get a string type by using the String top level object, like so: ${String[some text]}, or ${String[${MyVariable}]} -- note that if MyVariable is declared as a string, this would be silly to do. ${String[some text].Equal[Some other text]}.. and if MyVariable is a string: ${MyVariable.Equal[some text]}

Hopefully that gets you by. Let me know if you need further info

Aanya
GamingTools Subscriber
Posts: 18
Joined: Thu Jan 27, 2005 5:15 am

Post by Aanya » Thu Feb 10, 2005 4:39 am

Thanks Lax, thats just what i needed. :)

Post Reply