【发布时间】:2012-06-27 11:16:51
【问题描述】:
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
请问我怎么能这么说?
【问题讨论】:
标签: 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
请问我怎么能这么说?
【问题讨论】:
标签: c# winforms string parsing integer
使用字符串类的 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
【讨论】:
没有采用范围的int.Parse,因此:
Substring,然后在子字符串上使用int.Parse
所以:
x = int.Parse(abc.Substring(0,2));
等
【讨论】: