I have an int[]:
RXBuffer[0], RXBuffer[1],..., RXBuffer[9]
where each value represents an ASCII code, so 0x31 represents 1, 0x41 represents A.
How do I convert this to a 10 character string ?
So far I’ve tried Data = RxBuffer.ToString();. But it shows Data equals to System.Int32[] which is not what my data is.
How can I do this?
Assuming the “int array” is values in the 0-9 range (which is the only way that makes sense to convert an “int array” length 10 to a 10-character string) – a bit of an exotic way:
But pretty efficient (the
char[]is right-sized automatically, and the string conversion is done just with math, instead ofToString()).Edit: with the revision that makes it clear that these are actually ASCII codes, it becomes simpler:
Although frankly, if the values are ASCII (or even unicode) it would be better to store it as a
char[]; this covers the same range, takes half the space, and is just: