Unterminated string literal

I have this method which is created on the fly through the solutionModel. In this method I want to use the split function. The line with the split function gives me the ‘unterminated string literal’ error. Does anybody have a clue what I can do about this? Tried some things but can’t see how I could fix the error.

Example code:

var script = "function TestMethod() {";
script += " var test = globals.testArray;";
script += " var counter = test.split('\n');";   // this line, specifically the split('\n'), gives the error
script += " application.output(counter.length);";
script += " }";

var addMethod = newform.newFormMethod(script);

Ok, got it to work by creating a global method which splits the input and returns the splitted output. But still, the compiler shouldn’t give an error right?!

Have you tried

script += " var counter = test.split('\\n');";

patrick:
Have you tried

script += " var counter = test.split('\\n');";

Yep, split takes a regular expression (or a String containing a regular expression), so you need the two backslashes.

hmm. A split(‘\n’) will work as expected. I think the problem here is that the method code is provided to the form method as

var test = globals.testArray;
var counter = test.split('
');
application.output(counter.length);

and that is not nice.

thanks guys, completely forgot to try the double backslashes. that did work!

do make a case of this if you want
because i dont think it should be needed to escape it…
Need to investigate it a bit more.

jcompagner:
do make a case of this if you want
because i dont think it should be needed to escape it…
Need to investigate it a bit more.

vote up.