Q
查找字符串
0
A
回答
4
2
你可以看看等号...
string yourString = "value=5412304756756756756756792114343986";
string integerPart = yourString.Split('=')[1];
1
Match match = new Regex("[0-9]+").Match("value=\"5412304756756756756756792114343986\"");
while(match.Success)
{
// Do something
match = match.NextMatch();
}
2
您可以使用char.IsDigi吨 喜欢的东西。
string str = "value=5412304756756756756756792114343986";
List<char> justDigits = new List<char>();
foreach(char c in str)
{
if (char.IsDigit(c))
justDigits.Add(c);
}
string intValues = new string(justDigits.ToArray());
或者较短的版本
string intValues = new string(str.Where(char.IsDigit).ToArray());
2
您可以使用Regex
:
这太符合负数。你也可以迭代字符串中的每个字符,并检查它们是否是数字,但不是真正理想的解决方案,因为它可能是一个瓶颈。
编辑:在您输入的数字大于long。对于这样的数字,你可以使用从框架4.0开始的BigInteger
相关问题
- 1. 查找字符串
- 2. 查找字符串
- 3. 查找字符串
- 4. 查找字符串
- 5. 查找字符串
- 6. 查找字符串
- 7. 查找字符串
- 8. 查找字符串
- 9. 查找字符串
- 10. 查找字符串
- 11. 查找字符串
- 12. 查找字符串
- 13. 查找字符串
- 14. 查找字符串
- 15. 查找字符串
- 16. 查找字符串中的字符串
- 17. 在字符串中查找字符串
- 18. 查找字符串中的字符串
- 19. 查找字符串中的字符串
- 20. 在字符串中查找字符串
- 21. 查找其他字符串
- 22. 查找字符串AS3
- 23. 查找部分字符串
- 24. 查找链接字符串
- 25. 查找字符串中的
- 26. 查找字符串的Python
- 27. Jboss JNDI查找字符串
- 28. 查找类似字符串
- 29. InterviewStreet查找字符串
- 30. 查找字符串的
字符串中的''是否是故意的? –
你想要数字部分是一个整型还是一个字符串?值看起来太大,不能成为'int' –
@SteveHaigh它实际上太大了,甚至不能成为'long'。 –