String help

Hmm, I’m beyond frustrated at this point with unity. Why aren’t simple javascript string manipulation functions not present?

Seriously? or Am I just not using the right functions?

var currentParams = srcParams.split("");
		
		for (var i in currentParams)
		{
			var keyValue = currentParams[i].split("=");
			for (var j in keyValue)
			{
				var key = keyValue[j];
				var value = keyValue[j+1];
				
				if (key == "uid")
				{
					userId = value;
				}
			}
		}

.split doesn’t exist… Split exists, however that doesn’t take any parameters.

Because Unity uses Mono/.net. Hence, you use .net string functions, and all 3 Unity languages work with with them basically the same way. Plus they didn’t have to spend a lot of time implementing all of that functionality again when Mono already has it.

–Eric

Could you post a link to a reference page for the usage? I looked it up on Dot net and I still get the same old String usage references, none of which work.

For example:

public function Split(Char[ ], int) : String[ ];

so I did

var currentParams = srcParams.Split(“”, 3);

Unity’s response to that:
…No appropriate version of ‘String.Split’ for the argument list ‘(String, int)’ was found.

Any help is appreciated.

It would be really helpful if Unity3d could provide some example page on the usage of this.

Yeah, it needs to be a char like the docs say and not a string. UnityScript’s way of handling chars is a tad awkward:

var currentParams = srcParams.Split(""[0], 3);

You can get a char from any character of a string, like

var myChar = "foobar"[3];

would make myChar “b”.

–Eric

I too found the differences between Unity’s JavaScript (formerly known as UnityScript) and real JavaScript very annoying at first.

So, I wrote this:

There is also an overloaded method - which I find more useful -, you can use this with a single char. Not sure if it is any use in your case as you cannot specify the maximum number of strings returned:

// Javascript - I don't do Javascript, somebody please correct me if this is incorrect!!!
var currentParams = srcParams.Split('');

// C#
string[] currentParams = srcParams.Split('');

Ta

JT