I'm having a tough time trying to replace some \_
in some text in JS.
I've tried various combinations with fromCharCode
and split
but cannot seem to find success.
In all these cases the output is identical to the input, I can't rip out or replace the junk characters. It seems the backslash-underscore is invisible to JS. Wondering if it's related to the string being unicode?
Suggestions appreciated!
let v1 = {
s: "生病以后,爸爸\_什么\_酒\_都\_不\_能喝了"
}
let v2 = { ...v1 } // copy
let v3 = { ...v2 } // copy
v2.s = v2.s.replace(/\\/g, "X")
v3.s = v3.s.split(String.fromCharCode(92)).join("Y")
console.log("v1", v1)
console.log("v2", v2)
console.log("v3", v3)
At this point I might mess with a sed script ;.;
related checked do not solve: Javascript and backslashes replace Replace back slash (\) with forward slash (/) Converting backslashes into forward slashes using javascript does not work properly?