Showing results for 
Search instead for 
Did you mean: 

remove non-printable characters

I have a character stream I have recieved from a device that contains non printable characters with in it. I want to remove these characters to make parsing easier.

My thoughts were to turn the string into a character array and using a for loop remove all char outside the range of a-z, A-Z, 0-9 [SPACE] [/n] then convert the character array back to a string. This seems resource hungery but I see no other alternative.

0 Kudos
Message 1 of 6

What about symbols?


I don't consider it resource hungry.  I wouldn't turn it into an array of characters.  I would just work on the string.


But there is probably a way to create a Regex that could do what you want and do a search and replace with it.

Message 2 of 6

I hadn't considered search and replace


0 Kudos
Message 3 of 6

Actually, you original idea was good, it just needs a bit of tweaking.  Converting a string to or from a U8 array in LabVIEW is an in-place operation and will cost you essentially nothing, since the two arrays are actually the same.  Once you have the U8 array, you can use a bucket brigade algorithm to traverse your array.  You can find details of the bucket brigade algorithm here (look at the fourth example).  It is a very useful trick for using a single pass to remove arbitrary data from an array efficiently.  In your case, use the array element to switch a case structure.  This should be faster than a regex search and replace or using the search and replace VI multiple times.

This account is no longer active. Contact ShadesOfGray for current posts and information.
Message 4 of 6

But, you'd better make that last "\n", not "/n". For all the escaped but printable characters (space, tab, NL, etc.) you use a backslash, not a forward slash and make sure you are writing your regex string in "\ code" display or it still won't interpret them correctly.




To err is human, but to really foul it up requires a computer.
The optimist believes we are in the best of all possible worlds - the pessimist fears this is true.
Profanity is the one language all programmers know best.
An expert is someone who has made all the possible mistakes.

To learn something about LabVIEW at no extra cost, work the online LabVIEW tutorial(s):

LabVIEW Unit 1 - Getting Started</ a>
Learn to Use LabVIEW with MyDAQ</ a>
0 Kudos
Message 5 of 6

One possible solution (very simple):




0 Kudos
Message 6 of 6