Re: How to convert char[] to int?
Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance
Hi MilanB,
The method to convert a char[] to string is like this.
string s = new string(char[]);
int i = Int32.Parse(s);
On Sat, 07 May 2005 12:20:01 +0200, MilanB <MilanB@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
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" wrote:
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" <MilanB@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:9A32C5D4-0C6E-4500-BB80-BC50AD8DF187@xxxxxxxxxxxxxxxx
> Hello
>
> How to convert char[] to int?
>
> Thanks
--
Happy coding!
Morten Wennevik [C# MVP]
.
Relevant Pages
- Re: custom Throw() function
... always throw an exception, so you need to place a return statement after the ... Nicholas Paldino [.NET/C# MVP] ... > But I get 'Compiler Error CS0161: not all code paths return a value'. ... (microsoft.public.dotnet.languages.csharp) - System.InvalidCastException when trying to call a web service that
... call on a web server for my company. ... Exception Details: System.InvalidCastException: Specified cast is not valid. ... sourceControl, String eventArgument) +18 ... (microsoft.public.dotnet.framework.webservices) - Specified cast is not valid exception
... I am getting a "Specified Cast is not valid" exception on my ... I am trying to populate a datagrid. ... ERROR MESSAGE: ... (microsoft.public.dotnet.framework.aspnet) - Re: GeoTools 2.0 problem with LINE_CAP_ROUND
... > with this java code: ... > bat this not work. ... If so, what compiler error do you get, and where? ... If so, what exception do you get, and where? ... (comp.lang.java.programmer) - InvalidCastException in DataGrid
... I have a DataGrid on a WinForm into which I am loading a ... I have try/catch blocks around all ... with the additional information "Specified cast ... How can I trap this exception? ... (microsoft.public.dotnet.framework) |
|