How to use String functions in VASSAL

USING STRING FUNCTIONS IN VASSAL

Yes, you can use string functions in Vassal! In a beanshell "expression", java string functions are available for checking length, finding substrings, etc.

Examples of string voodoo I have successfully accomplished in Vassal:

EXAMPLE #1 Here is an expression I have used to check if the current location is listed in the table of victory objectives spaces (and give me 1 or 0 as the result). In this case I have two different AP_Objectives tables (AP_Objectives_0 and AP_Objectives_1) and I pick which one based on the global Variant property:

'''("AP_Objectives_"+Variant).contains(LocationName) ? 1 : 0'''

So the AP_Objectives_0 string looks something like "Metz Strasbourg Frankfurt Stuttgart Berlin ..." etc etc. Doesn't even matter for me that some names have spaces in them e.g. "Port Said", since none of the individual VP space names in the game will fall foul of such a search.

I don't "really" need to use the beanshell conditional syntax, it was just convenient for me to translate into an integer.

EXAMPLE #2 Here I take a LocationName in the format "Turn 17", delete everything that isn't a 0-9 digit, and parse back into an integer value (which in the example of "Turn 17" would give me 17):

Integer.parseInt(LocationName.replaceAll("[^0-9]",""))

EXAMPLE #3 Extracting the first word in a Property:

yourString.replaceFirst(" .*","")

I hope this is helpful! It was hard-won knowledge since I couldn't find functioning examples anywhere!

A complete list of the String class methods can be found at e.g. Oracle Java Docs