检测 JavaScript 中的不可打印字符
JavaScript 中是否可以检测二进制数据?
我希望能够检测二进制数据并将其转换为十六进制以便于可读性/调试。
经过更多调查后,我意识到检测二进制数据不是正确的问题,因为二进制数据可以包含常规字符和不可打印字符。
Outis 的问答 (/[\x00-\x1F]/) 确实是我们在尝试检测二进制字符时所能做的最好的事情。
注意:您必须从 ASCII 字符串序列中删除换行符和可能的其他字符,以使检查真正起作用。
Is it possible to detect binary data in JavaScript?
I'd like to be able to detect binary data and convert it to hex for easier readability/debugging.
After more investigation I've realized that detecting binary data is not the right question, because binary data can contain regular characters, and non-printable characters.
Outis's question and answer (/[\x00-\x1F]/) is really the best we can do in an attempt to detect binary characters.
Note: You must remove line feeds and possibly other characters from your ascii string sequence for the check to actually work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果“二进制”是指“包含不可打印的字符”,请尝试:
如果空格被视为非二进制数据,请尝试:
如果您知道字符串是 ASCII 或二进制,请使用:
或:
If by "binary", you mean "contains non-printable characters", try:
If whitespace is considered non-binary data, try:
If you know the string is either ASCII or binary, use:
or: