09-29-2013 08:26 PM
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.
09-29-2013 09:07 PM
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.
09-29-2013 09:18 PM
I hadn't considered search and replace
09-30-2013 07:57 AM
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.
09-30-2013 08:03 AM
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.
Cameron
04-03-2023 10:22 AM
05-15-2024 07:33 AM
This is an old thread but this was my solution
It almost seems like there should be a function to do this