Hi
I get data from a serial port in ascii characters. only numeric characters are allowed and I check for illegal characters with regular expressions. This part works fine and if an illegal character presents itself the regular expression method catches it and display them in variable m. then I take the string and split it into the different words wich consists of 4 bytes each. the illegal character normaly sits as byte 1 for example "q123" the problem is that if a word contains a character other than numeric i need to change the 4 bytes to "0" and it need to be "0000" then.
should i change it in the string with string.Replace before I split it into an array or when it's an array and how?
procomp65 0 Light Poster
Recommended Answers
Jump to PostYou could make an array of 4 byte long arrays... Then you could just replace the 4-byte arrays where position 0 has an invalid character with a buffer full of 0's.
Does that make sense?
Jump to PostSo just so we're clear, you have a string, you split it up into chunks of 4 characters each, but it's basically an array of strings?
Why not just loop through the elements, test each one, and for each one that contains an illegal character, simply set the element …
All 7 Replies
JuhaW 19 Light Poster
procomp65 0 Light Poster
alc6379 120 Cookie... That's it Team Colleague
procomp65 0 Light Poster
apegram 302 LINQ! Team Colleague
Geekitygeek commented: neatly coded, pretty much what i would have done +1
procomp65 0 Light Poster

AnthonyMG
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.