在C#中将字符串转换为整数 [英] Convert string to integer in C#
本文介绍了在C#中将字符串转换为整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Iam尝试将字符串转换为整数。我无法转换。抛出错误
Iam trying to convert string to integer. i couldnt convert. It throws error as
Input string was not in a correct format.
string snewidstring = "462414720-60TX6E0088";
int snewid = Convert.ToInt32(snewidstring);
如何将此字符串转换为整数。
我尝试过:
How to convert this string to integer.
What I have tried:
<pre>string snewidstring = "462414720-60TX6E0088";
int snewid = Convert.ToInt32(snewidstring);
推荐答案
这个怎么样:
Int32.TryParse Method(String,Int32)(System) [ ^ ]
How about this:
Int32.TryParse Method (String, Int32) (System)[^]
string snewidstring = "462414720-60TX6E0088";
int storein;
int.TryParse(snewidstring, out storein);
嗯,好像你至少试过......你将不得不删除 - 和TX和E会给你你这么多,所以你必须去Int64。
这是你的字符串转换的方式。
Well, it seems you at least tried... You're going to have to remove the - and TX and E which will give you a large number, so you'll have to go Int64.
This is how your string will convert.
string snewidstring = "4624147206060088";
Int64 snewid = Convert.ToInt64(snewidstring);
这篇关于在C#中将字符串转换为整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文