Page 1 of 1

[Solved] String concatenation in JS function called from LC

Posted: Thu Apr 04, 2013 7:03 pm
by Cairoo
Dear experts

I am using LiveCode's browser support, to display Maths. I make calls to JavaScript functions and some of these functions take arguments. One of the JavaScript functions must append string data to its arguments, but fails to do so for no appearent reason. The concatenation only fails when the function is called from my LiveCode app. It works without a problem if the function is called from outside of my LiveCode app.

The LC documentation says that LC internally treats the arguments as null terminated strings. Could that be the cause of the problem? How can it be fixed? It should be noted that my dev environment is Microsoft Windows 8.

Thanks in advance

Cairoo

Edit: I've created and attached a sample project to demonstrate the problem. Please have a look.

Re: String concatenation in JS function called from LC

Posted: Fri Apr 05, 2013 10:46 am
by Cairoo
Never mind; I found the solution.

All I had to do was to write a JavaScript function that removes the null terminator from the argument. It works now.

Here's the JavaScript code for removing the null terminator from a string:

Code: Select all

function removeNullTerminator(theNullTerminatedString) {
    var theArray = theNullTerminatedString.split('');
    theArray.splice(theArray.length - 1, 1);
    var newString = theArray.join('');
    return newString;
}
Thanks for reading.