0
A
回答
10
最簡單的方法是去掉了時間和解析:
var input = "1.0.0.1";
int number = int.Parse(input.Replace(".", ""));
注意 - 如果字符串不是一個數字,一旦週期剝離出來這個版本會拋出異常。如果你不希望這種行爲,你可以使用int.TryParse
var input = "1.0.0.1";
int number;
int.TryParse(input.Replace(".", ""), out number);
4
你可以嘗試
int.Parse(myString.Replace(".", ""))
1
Int32 num;
String numString = "1.0.0.1";
Boolean success = Int32.TryParse(numString.Replace(".",""), out num);
然後你就可以測試的成功是真正試圖使用NUM整數之前。
1
string number = "1.0.1.0.1";
var convertedString = int.Parse(number.Replace(".",""));
這應該工作。
1
如果你的字符串是靜態
int number = Convert.ToInt32("1.0.0.1".Replace(".", ""));
其他
int number = Convert.ToInt32(yourstringvariable.Replace(".", ""));
相關問題
- 1. 將字符串轉換爲整數C#
- 2. 將小數點後的字符串轉換爲整數
- 3. 在C++中將字符數組轉換爲整數字符串
- 4. 無法在C++中將整數字符串轉換爲整數
- 5. 將整數轉換爲字符串
- 6. 將字符串轉換爲整數
- 7. 將字符串轉換爲整數
- 8. Python將字符串轉換爲整數?
- 9. Swift:將字符串轉換爲整數
- 10. 將字符串轉換爲整數
- 11. 將字符串轉換爲整數
- 12. 將字符串轉換爲大整數?
- 13. 將字符串轉換爲整數?
- 14. Java將字符串轉換爲整數
- 15. 將字符串轉換爲整數
- 16. 將整數轉換爲字符串
- 17. 將字符串轉換爲整數
- 18. 將字符串整數的JSON字典轉換爲整數
- 19. 將多個小數轉換爲整數的SQL轉換字符串
- 20. 將字符串轉換爲整數數組c
- 21. 將矩陣字符串數組轉換爲整數矩陣? C++
- 22. 將包含幾個數字的字符串轉換爲整數
- 23. 將字符數組轉換爲整數
- 24. 將小端字符串轉換爲整數
- 25. 將字母數字字符串轉換爲整數格式
- 26. 如何將字符串轉換爲目標C中的整數?
- 27. 將部分字符串轉換爲turbo C++中的整數
- 28. 將字符串轉換爲c中的整數#
- 29. 如何將字符串轉換爲C++中的整數?
- 30. 將四個字符的字符串轉換爲長整數
EWWW - 太慢! – Alex 2012-03-07 09:06:35