请求编写Scilab的WeekDay()函数(支持select case与大小写兼容)
Scilab实现WeekDay()函数
函数代码
function num = WeekDay(dayStr) // 统一转换为小写,实现不区分大小写匹配 lowerDay = lower(dayStr); select lowerDay case "周一" then num = 1; case "周二" then num = 2; case "周三" then num = 3; case "周四" then num = 4; case "周五" then num = 5; case "周六" then num = 6; case "周日" then num = 7; else error("输入无效,请输入周一至周日的字符串"); end disp(num); endfunction
功能演示控制台输出
测试不同格式的输入:
// 测试常规输入 WeekDay("周一") // 输出: 1 // 测试大写输入 WeekDay("周日") // 输出: 7 // 测试混合大小写输入 WeekDay("周三") // 输出: 3 // 测试无效输入 WeekDay("星期八") // 输出: !--error 999 // 输入无效,请输入周一至周日的字符串
内容的提问来源于stack exchange,提问作者Priyanka Gosai
相关产品推荐
相关产品推荐

