Main Site Documentation

Convert String to Integer


#1

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?


#2

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


#3

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?


#4

Mike got it first lol, removed code


#5

@ Mike -

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


#6

try Int32 class