简体   繁体   English

不可打印字符的问题

[英]Issues with non-printable characters

I'm using a bar code scanner to read 2-D data matrix, UID barcodes into a web application. 我正在使用条形码扫描仪将二维数据矩阵和UID条形码读取到Web应用程序中。 UIDs contain the non-printable ASCII characters RS, GS and EOT. UID包含不可打印的ASCII字符RS,GS和EOT。 My problem is that the browser automatically appends the HTML Code to the front of each ASCII char and since there are no HTML codes defined for RS, GS and EOT it throws a fit. 我的问题是浏览器会自动将HTML代码附加到每个ASCII字符的前面,并且由于没有为RS,GS和EOT定义的HTML代码,因此很合适。

I'm using Javascript to dynamically build a string from the scanned in data, here is a sample of what I get back 我正在使用Javascript从扫描的数据中动态构建字符串,这是我得到的示例

091[041)062>030RS 091 [041)062> 030RS

As you can see, the RS char is given a value(030) that doesn't exist as a standard HTML Code. 如您所见,RS字符的值(030)作为标准HTML代码不存在。 Another issue seems to be when a regular alphabetic character is hit the browser seems to treat it as a carriage return(CR), so the values that precede them are shown briefly then disappear. 另一个问题似乎是当敲击常规字母字符时,浏览器似乎将其视为回车符(CR),因此它们前面的值会短暂显示,然后消失。

I want to be able to show the whole string in the browser textbox. 我希望能够在浏览器文本框中显示整个字符串。 I have a javascript function that looks for these non-printable chars and swaps them for letters, ie RS will be replaced with a concatenation of 'R' and 'S'. 我有一个javascript函数,用于查找这些不可打印的字符,并将它们交换为字母,即RS将替换为“ R”和“ S”的串联。 But I still have the issue of the browser going crazy as explained above. 但是如上所述,我仍然有浏览器发疯的问题。 Any insight is appreciated. 任何见解均表示赞赏。

UPDATE: 更新:

Hi Mathew, sorry for not being more detailed. 嗨,马修(Mathew),对不起,我没有详细介绍。 I'm tried the replacement function as follows with the replace all flag: 我尝试了如下替换功能,并带有replace all标志:

String.replace(/(030)|(029)|(004)/g,""); String.replace(/(030)|(029)|(004)/ g,“”);

Problem is that it replaces the entire string, so 问题是它替换了整个字符串,所以

091[041)062>030RS 091 [041)062> 030RS

becomes 变成

/(030)|(029)|(004)/g /(030)|(029)|(004)/ g

I'm not sure if I understand your problem exactly, but why not just run the replacement function on the string before writing it to the DOM? 我不确定我是否能完全理解您的问题,但是为什么不先在字符串上运行替换函数,然后再将其写入DOM? If the non-printable characters are never printed, there won't be any issues. 如果不能打印的不可打印字符不会有任何问题。


Response to Update 回应更新

You can match non-printable characters with hex values using regular expressions. 您可以使用正则表达式将不可打印的字符与十六进制值进行匹配。 Check this out for details. 查看以获取详细信息。 Here's a quick example: 这是一个简单的示例:

uid.replace(/[\x30\x29\x04]/g,"")

(Note that the replace() function is called on the string instance, not on String itself.) (请注意, replace()函数是在字符串实例上调用的,而不是在String本身上调用的。)

To make this more effective, consider using a range of non-printable characters (ie [\\x00-\\x1F\\x80-\\xFF] ). 为了使其更有效,请考虑使用一系列不可打印的字符(即[\\x00-\\x1F\\x80-\\xFF] )。

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

相关问题 在JavaScript中检测不可打印的字符 - Detect non-printable characters in JavaScript 如何替换不可打印的 unicode 个字符 (Javascript) - How to replace non-printable unicode characters (Javascript) Internet Explorer中的Javascript函数上缺少不可打印的字符 - Non-printable characters missing on Javascript function in Internet Explorer 删除不可打印的字符 - Removing non-printable character 如何模拟适用于 JavaScript 中的字母数字和不可打印字符的跨浏览器按键? - How do I simulate a cross browser key press that works for alphanumeric and non-printable characters in JavaScript? 替换在工作笔记中不起作用的不可打印的 ASCII 字符 - Replacing non-printable ASCII character not working in work notes JavaScript中的对象属性是否可能不可打印但可迭代? - Is it possible for a object property in JavaScript to be non-printable but iterable? Javascript Regex 将文本字段限制为仅数字(必须允许不可打印的键) - Javascript Regex to limit Text Field to only Numbers (Must allow non-printable keys) 使用不可打印的字符(如CTRL,ALT或Shift键)镜像输入内容 - Mirroring input content with non-printable chars like CTRL, ALT or shift key 从Javascript读取不可打印的字符 - Read non printable characters from Javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM