I'm still new to JavaScript (VB.NET previously) and coming to grips with the language. I have a problem where a string I'm passing around in JavaScript has somehow got Unicode escape characters in it (0x5206, left-to-right mark) that I need to strip out. I can do this with a dumb loop checking for the existence of the unicode character and stripping it out, but I should be able to do this with a .replace(regex). However after a couple of hours trying I need help with it (first time doing regex).
// Convert from JS date format to dotnet ticks
function getNetDateTime(JSDate, dateortime) {
var convStr = JSDate.toLocaleString();
var tryRegEx = convStr.replace(/\u5206/g, "");
var tempStr = "1/01/2000 10:00:00 AM";
var stripStr = "";
for (var i = 0; i < convStr.length; i++) {
if (convStr.charCodeAt(i).toString() != "8206") stripStr = stripStr + convStr.charAt(i);
}
alert(new Date(tempStr).toString());
alert(new Date(tryRegEx).toString());
alert(new Date(stripStr).toString())
var datetime = ((new Date(stripStr).valueOf() + unixEpoc) * pcTicks).toString();
return datetime;
}
In the code above, tempStr and stripStr give the correct date but not tryRegEx (gets invalid date as the Unicode escape char isn't stripped out). I'm fairly sure the regex expression is correct so not really sure why regex isn't working for me (so I can ditch the loop).
Thanks for any pointers. I'm sure I'm overlooking something basic here... :-)
5206 or 8206? Pick one :) If it's 8206, you want \u200E
(8206 in hex). If it's 5206 you want \u1456
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With