c# - 如何将字符串的特定字符解析为整数?

标签 c# winforms string parsing integer

string abc = "07:00 - 19:00"
x  = int.Parse(only first two characters) // should be 7
y  = int.Parse(only 9th and 10th characters) // should be 19

请问我怎么说呢?

最佳答案

使用字符串类的Substring方法提取所需的字符集。

string abc = "07:00 - 19:00";
x  = int.Parse(abc.Substring(0,2)); // should be 7
y  = int.Parse(abc.Substring(8,2)); // should be 19

关于c# - 如何将字符串的特定字符解析为整数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11202236/

相关文章:

c# - 如何增加 Asp .Net MVC 5 中的 session 超时时间?

c# - C# 中最好的 "curl -u"等价物

c# - 尝试 Convert.ToInt32(value) 时指定的转换无效

c# - 使用 Visual Studio 2017 在 SQL 数据库中插入数据

winforms - 如何在Powershell中添加计时器以在一定时间后退出表单

c++ - 给定一个字符串,每当你看到单词 "ant"时,将单词 "termite"替换为字符串

c++ - Turbo C++ 的字符串问题

c# - 通过 RealProxy 引用参数

winforms - 可以将 WinForms 嵌入到 VCL Delphi 应用程序中吗?

python - 在python中将float转换为不带点/逗号的字符串