Ambiguous match found when calling String.Split()

222 views Asked by At

I'm programming in JScript.NET which is similar to C# . I want to split a string on multiple characters, in this case " - ".

The problem is when I do that like this (which should be the way to do it according to this thread):

var text = "test - test2";

var array = [" - "];

var val = text.Split(array, StringSplitOptions.None);

I get "Ambiguous match found". This is because the String class has both a Split(Char[], StringSplitOptions) and a Split(String[], StringSplitOptions) function, and the compiler doesn't know which one to use.

So my question is then. How do I tell the compiler that I'm using a string array when the arrays in JScript.NET are dynamically typed?

Edit: As far as I know, JScript.NET use the same APIs as C#. So this is the String class I'm using. However, I think the syntax is the same as JavaScript. Maybe someone could confirm this?

Edit2: So if there is a way to enforce a type in JScript.NET so the compiler knows which type is used, I guess that would be the answer for my case as well? JScript.NET does not have the same syntax as C#.

1

There are 1 answers

0
Jonatan Stenbacka On

I figured it out once I realized I was coding in JScript.NET and not JScript, which led me to a bunch of useful guides. One of them specifically mentioned how to create typed arrays.

It turns out it was a easy as this:

var array : String[] = [" -"];