我正在尝试在RUBY中编写一个函数来确定给定的字符串是否是有效的牌照。有效牌照的格式如下:3个大写字母,后跟破折号,后跟4个数字。 EX:HES-2098
。
我编写了以下函数,但需要一些帮助才能进行模式匹配。
def liscence()
plate = "HES-2098"
plateNo = plate.upcase
if(plate.length == 8)
if(plate == plateNo)
if(/\A-Z\A-Z\A-Z\-\d{4}/.match(plate))
puts "valid"
else
puts "invalid"
end
else
puts "First 3 letter must be uppercase"
end
else
puts "Only 8 char long"
end
end
liscence()
答案 0 :(得分:2)
func chooseAlert(){
let alert = UIAlertController(title: "Upload Image", message: "Choose Source For Image.", preferredStyle: .ActionSheet)
let cameraAction = UIAlertAction(title: "Take Photo", style: .Default, handler: { (action:UIAlertAction) -> Void in
dispatch_async(dispatch_get_main_queue())
{
// self.performSelector(#selector(self.useCamera), withObject: nil, afterDelay: 1.0)
self.useCamera()
}
})
let cameraRollAction = UIAlertAction(title: "Use Photo", style: .Default, handler: { (action:UIAlertAction) -> Void in
dispatch_async(dispatch_get_main_queue())
{
self.useCameraRoll()
}
})
let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel){
(action) in
print(action)
}
alert.addAction(cameraAction)
alert.addAction(cameraRollAction)
alert.addAction(cancelAction)
presentViewController(alert, animated: true, completion: nil)
}
答案 1 :(得分:2)