String Comparison in Unity JS

The Unity JS String class appears to not support the JS “match” function for comparing strings.

Is there a quick way to compare two strings in Unity JS that returns a boolean?

Yes: “==”.

E.g.

var s1 : String;
var s2 : String;
var s3 : String;

function Update () {
	s1 = "A";
	s2 = "B";
	s3 = "A";
	Debug.Log(s1 == s2);
	Debug.Log(s1 == s3);
}

I should have been more precise …

I need to do a match()-like partial-string comparison wherein I would compare string A to string B and get a boolean (1) if string A contains string B and a boolean (0) if it does not.

Not a whole string comparison, just part.

http://msdn2.microsoft.com/en-us/library/system.string_members.aspx

You can use

if ("Hello World".IndexOf ("World") != -1)
{
   is a substring
}

The ECMAScript match method is not just a substring test method. It does regular expression matching.

If you want to test if a string is a substring of another string use IndexOf:

   if ( longString.IndexOf(subString) > -1 ) {
       ...
   }

Edit: Oh!.. Joe has already answered that…

If you want to do regluar expression matching take a look at System.Text.RegularExpressions.Regex

Sweet!

Thanks for all the help, you so-smart-its-scary OTEE-guys.