1
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

请问我怎么能这么说?

4

2 回答 2

7

使用字符串类的 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
于 2012-06-26T07:05:17.510 回答
3

没有int.Parse一个范围,所以要么:

  • 编写自己的解析器(yeuch)
  • 先使用Substring,然后int.Parse在子字符串上使用

所以:

x = int.Parse(abc.Substring(0,2));

ETC

于 2012-06-26T07:05:54.270 回答