简体   繁体   English

从字符串中剥离javascript unicode字符8206

[英]Stripping javascript unicode character 8206 from a string

I'm still new to JavaScript (VB.NET previously) and coming to grips with the language. 我还是JavaScript的新手(之前是VB.NET)并且正在掌握这门语言。 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. 我有一个问题,我在JavaScript中传递的字符串在某种程度上得到了Unicode转义字符(0x5206,从左到右标记)我需要删除。 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). 我可以通过一个哑循环检查是否存在unicode字符并将其剥离出来,但我应该可以使用.replace(正则表达式)执行此操作。 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). 在上面的代码中,tempStr和stripStr给出了正确的日期,但没有给出tryRegEx(因为Unicode转义字符没有被删除,所以获取无效日期)。 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? 5206或8206? Pick one :) If it's 8206, you want \‎ (8206 in hex). 选择一个:)如果它是8206,你想要\‎ (8206十六进制)。 If it's 5206 you want \ᑖ 如果它是5206你想要\ᑖ

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM