Removing control ASCII characters

时间:2015-10-29 16:01:00

标签: javascript hex character ascii

function RemoveASCIIControlCharacters(xmlString) {
    var cleanXmlString = xmlString.replace(/VT/g,'');
    cleanXmlString = cleanXmlString.replace(/SUB/g, '');
    return cleanXmlString;
}

Please replace VT and SUB with real control character.

The removal of the VT control character works. However the removal of the SUB control character fails.

How do I filter out the SUB(0x1A) control character?

2 个答案:

答案 0 :(得分:0)

使用\ xY,其中Y是十六进制字符代码,例如。对于两者:

return cleanXmlString.replace(/[\x0b\x1a]/g, ''));

答案 1 :(得分:0)

您可以使用八进制字符转义和范围:/[\0-\32]/g