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 PostString can't be modified in .net. You could use array of byte or array of char. Ascii code could be presented as byte (8 bits).
byte[] buffer=new byte[4096];
If string length will be short it also quite efficient to use rebuild new string with replace
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.