1

I am using the Fiddler web debugger which uses FiddlerScript which is based on JScript.NET. I'm trying to do some simple .NET string parsing but it fails with error "More than one method or property matches this argument list". For example:

        var ahraw: String = "one, two, three, four";
        var ah: Array = ahraw.Split([',', ' '], System.StringSplitOptions.RemoveEmptyEntries);
        for (var i in ah) {
            FiddlerObject.alert("\"" + ah[i] + "\"");
        }

enter image description here

String.Split has these prototypes:

Split(Char[], Int32, StringSplitOptions)
Split(String[], Int32, StringSplitOptions)
Split(String[], StringSplitOptions)
Split(Char[], StringSplitOptions)
Split(Char[], Int32)
Split(Char[])

Even if I add an Int32 and run it like ahraw.Split([',', ' '], 99, System.StringSplitOptions.RemoveEmptyEntries); or ahraw.Split(", ", 99, System.StringSplitOptions.RemoveEmptyEntries); it still finds multiple methods. Is it possible to force the specific .NET type? Something like var sep: String doesn't work either.

Of course there are other ways to split a string in JScript such as split() (note the lowercase s). I'm more interested in how I can get around this issue for when there's no javascript equivalent for the function I need to call, so I have to call a .NET funciton.

Borislav Ivanov
  • 4,684
  • 3
  • 31
  • 55
Jay
  • 319
  • 3
  • 12
  • May be this is just not possible with JScript.net. Have you tried to use C# instead of JScript.net (can be changed in the Options dialog of Fiddler). – Robert Mar 16 '20 at 18:37
  • Thanks, looks interesting. – Jay Mar 16 '20 at 22:16

1 Answers1

1

As mentioned in the comments, these days it would probably be easier to just use C# as a scripting language (could be set in Tools -> Options -> Scripting -> Language).

If you however have/want to stick to JScript.NET (e.g. if you already have complex customizations), you can work around the problem by declaring typed array for the separators, otherwise the compiler cannot distinguish which of the Split(String[], StringSplitOptions) and Split(Char[], StringSplitOptions) overloads to call.

    var ahraw: String = "one, two, three, four";
    var separators: Char[] = [',', ' '];
    var ah: Array = ahraw.Split(separators, System.StringSplitOptions.RemoveEmptyEntries);
    for (var i in ah) {
        FiddlerObject.alert("\"" + ah[i] + "\"");
    }
Borislav Ivanov
  • 4,684
  • 3
  • 31
  • 55
  • This is the right answer. I was doing `var separators: String = ", ";` but I should have been doing `var separators: String[] = [", "];` – Jay Mar 29 '20 at 06:25