G
Guest
Hello
How to convert char[] to int?
Thanks
How to convert char[] to int?
Thanks
Chris Taylor said:Hi,
If I understand correctly you have a char[] of numeric digits and you want
to convert this to the integer number represented by the digits.
You could convert the char[] to a string then using int.Parse or
Contert.ToInt32.
To convert the char[] use System.Text.Encoding.ASCII.GetString(char[]).
Hope this helps
--
Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor
MilanB said:Hello
How to convert char[] to int?
Thanks
MilanB said:Hi
Thanks for replay...
When I use Convert.ToInt32, I get exception "Specified cast is not valid.",
With System.Text.Encoding.ASCII.GetString I get compiler error: " Argument
'1': cannot convert from 'char[]' to 'byte[]'"
int.Parse has not overload method to pass char[]
Sorry
Thanks
Chris Taylor said:Hi,
If I understand correctly you have a char[] of numeric digits and you want
to convert this to the integer number represented by the digits.
You could convert the char[] to a string then using int.Parse or
Contert.ToInt32.
To convert the char[] use System.Text.Encoding.ASCII.GetString(char[]).
Hope this helps
--
Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor
MilanB said:Hello
How to convert char[] to int?
Thanks
Hi
Thanks for replay...
When I use Convert.ToInt32, I get exception "Specified cast is not valid.",
With System.Text.Encoding.ASCII.GetString I get compiler error: " Argument
'1': cannot convert from 'char[]' to 'byte[]'"
int.Parse has not overload method to pass char[]
Sorry
Thanks
Chris Taylor said:Hi,
If I understand correctly you have a char[] of numeric digits and you want
to convert this to the integer number represented by the digits.
You could convert the char[] to a string then using int.Parse or
Contert.ToInt32.
To convert the char[] use System.Text.Encoding.ASCII.GetString(char[]).
Hope this helps
--
Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor
MilanB said:Hello
How to convert char[] to int?
Thanks
Morten Wennevik said:Hi MilanB,
The method to convert a char[] to string is like this.
string s = new string(char[]);
int i = Int32.Parse(s);
Hi
Thanks for replay...
When I use Convert.ToInt32, I get exception "Specified cast is not valid.",
With System.Text.Encoding.ASCII.GetString I get compiler error: " Argument
'1': cannot convert from 'char[]' to 'byte[]'"
int.Parse has not overload method to pass char[]
Sorry
Thanks
Chris Taylor said:Hi,
If I understand correctly you have a char[] of numeric digits and you want
to convert this to the integer number represented by the digits.
You could convert the char[] to a string then using int.Parse or
Contert.ToInt32.
To convert the char[] use System.Text.Encoding.ASCII.GetString(char[]).
Hope this helps
--
Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor
Hello
How to convert char[] to int?
Thanks