【发布时间】:2011-09-14 11:21:57
【问题描述】:
字段数据有 4 种可接受的值类型:
j
47d (where the first one-two characters are between 0 and 80 and third character is d)
9u (where the first one-two characters are between 0 and 80 and third character is u)
3v (where the first character is between 1 and 4 and second character is v).
否则数据将被视为无效。
字符串数据 = readconsole();
验证此输入的最佳方法是什么?
我正在考虑结合使用 .Length 和 Switch 子字符串检查。
即。
if (data == "j")
else if (data.substring(1) == "v" && data.substring(0,1) >=1 && data.substring(0,1) <=4)
....
else
writeline("fail");
【问题讨论】:
-
我知道语法无效,必须将字符串转换为整数和 console.writeline().etc 但你明白了。
标签: c# .net switch-statement substring