int类型数组中的字符串值 [英] string value in int type array
本文介绍了int类型数组中的字符串值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好朋友,我需要帮助
我有1英寸和0英寸的字符串.
现在,我想将该字符串值放入类型为int的数组中.
请帮助
例如
s ="10101111100011111";
hello frnds , i need help
i have string of 1''s and 0''s.
Now i want to take that string value in an array of type int.
please help
e.g
s="10101111100011111";
推荐答案
据我所知,没有直接的方法可以实现这一目标.请尝试以下代码:
As far as I know there is no direct method of achieving that. Try the code below:
public static int[] StringToInts(string myString)
{
List<int> ints = new List<int>();
string[] strings = myString.Split(',');
foreach (string s in strings)
{
int i;
if (int.TryParse(s.Trim(), out i))
{
ints.Add(i);
}
}
return ints.ToArray();
}
除非您有不同的要求,否则1个整数可以容纳这样的二进制(我想)字符串值:
Unless you have different requirements, 1 single integer can hold such a binary (I guess) string value:
int k = Integer.parseInt("10101111100011111",2);
:-)
:-)
这篇关于int类型数组中的字符串值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文