Alias string matching

mredge73

Member
I have a question about using alias and string matching:

I have this test script (test.ash)
Code:
void stringtest(string match)
{
    string TestString= "Monkey";
    print(TestString,"olive");

    if (TestString==match)
        print (match+" works","green");
    else
        print(match+" does not match","red");
}
Now I am trying to build an alias to make use of it but for some reason the strings are not matching correctly:
Code:
> alias test => ash import <test.ash> stringtest("%%");

String successfully aliased.
test => ash import  stringtest("%%")

> test Monkey

Monkey
Monkey does not match
Returned: void
But it works fine like this:
Code:
> alias test => ash import <test.ash> stringtest("Monkey");

String successfully aliased.
test => ash import  stringtest("Monkey")

> test

Monkey
Monkey works
Returned: void
I don't understand why the string is not matching but it is probably because I wrote the alias wrong, any help will be appreciated!
 

jasonharper

Developer
The substitution of %% in an alias is followed by a space, so in your test the parameter ended up with a value of "Monkey " - this would be more obvious if you printed some visible delimiter characters around the string. I'm not sure whether this is a bug, or if that space is actually necessary for aliases to work right in some circumstances, but in any case the problem can be avoided by using $string[%%] instead of "%%" - that form strips leading/trailing whitespace.
 
Top