Apparently, your raw string from rs232 does not get parsed correctly. Why do you process it so much? First you convert it to an array, then back to a string.
Please attach a small example with typical rs232 data contained in a diagram constant. Show us how you do all these conversions. What string do you get and what string do you want for the case structure?