0

I'm using a bar code scanner to read 2-D data matrix, UID barcodes into a web application. UIDs contain the non-printable ASCII characters RS, GS and 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.

I'm using Javascript to dynamically build a string from the scanned in data, here is a sample of what I get back

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. 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.

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, i.e. RS will be replaced with a concatenation of 'R' and '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. I'm tried the replacement function as follows with the replace all flag:

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

Problem is that it replaces the entire string, so

091[041)062>030RS

becomes

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

1 Answer 1

3

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? 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.)

To make this more effective, consider using a range of non-printable characters (i.e. [\x00-\x1F\x80-\xFF]).

2
  • You could encode the special characters in the standard % form, e.g., RS as %1E. Dec 23, 2010 at 21:42
  • @Loadmaster - how exactly does that work? I'm not familiar with that. Dec 23, 2010 at 22:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.