comma-backslash in javascript

Mar 10, 2011 at 9:20pm

comma-backslash in javascript

I’m trying to backslash out some commas in a textfile in js in such a way that outputting the string will give me something a messagebox likes. For example, if x is a string “foo, bar” I want outlet(0,x) to give me “foo,bar”.

the function below just returns a comma:

function readchunk()

{

var x = file.readstring(100);
var y = x.replace(“,”,”,”)
post(y, “n”);
outlet(0,y);
}

if I change the second line of the function to:

var y = x.replace(“,”,”-”)

I get “foo- bar” as expected.

if I change the second line of the function to:

var y = x.replace(“,”,”\,”)
//seemed like a fine thing to try

I get “foo\, bar”.

I can’t do a search/replace in the file I’m working on & just fix it from there. Any recommendations?

Thanks.

M

Never mind — it works if you use readline() instead of readstring(). Go figure. Leaving this here for the record…
M

#55449

You must be logged in to reply to this topic.