I recently transitioned from VB.NET to JavaScript, and I am still getting familiar with the language. I have encountered an issue where a string I'm working with in JavaScript contains Unicode escape characters (0x5206, left-to-right mark) that I need to remove. While I could achieve this by manually looping through the string and removing the characters, I believe there should be a more efficient way to do it using .replace(regex). However, despite my attempts over the past few hours, I haven't been successful yet and I would appreciate some help (as this is my first time working with 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 snippet above, while tempStr and stripStr provide the correct date, tryRegEx fails to do so (due to the Unicode escape character not being stripped out). Although I believe my regex expression is accurate, I am unsure why it is not functioning as expected (which means I still have to rely on the loop).
Any guidance or advice would be greatly appreciated. Perhaps I am missing something fundamental... :-)