Main Site Documentation

Convert String to Integer


Hi everyone,

I am using an RS232 serial port and getting information back as a byte array. The array is separated by a space; first half contains strings and the other half is integers. What’s the most efficient way to split these two components so that I am able to to access both the string and integer components?


I should also probably clarify that I can convert the byte array into a string and split it like that. But I was then unable to convert half of the the string to an integer


Split the string into parts using:

string s;
char[] seperator = new char[] {' '};
string[] parts = s.Split(seperator);

You can convert a string to an integer by:

string n = "123";
int x = Integer.Parse(n);

int y = Integer.Parse(parts[3]);

Does this help?


Mike got it first lol, removed code


@ Mike -

I don’t have the ‘Integer’ class available to me? My VS intellisense doesn’t populate it…


try Int32 class