楼主:
LPen (鸟人)
2023-01-26 05:33:48我最近遇到要处理 年龄的字串,我觉得我的写法很冗长,
不知道有没有更简洁的写法,比方用RegexMatch
我的写法是
text:="7y8m"
yposition:=instr(text,"y")
year:=substr(text,yposition-1)
mposition:=instr(text,"m")
mlength:=mposition-yposition-1
month:=substr(text,yposition+1,mlength)
Msgbox % "The age is" . year . "years" . month ."month old."
text:="7y8m"RegExMatch(text,"(\d{1,3})y(\d{1,2})m",age)Msgbox The age is %age1% years %age2% month old安捏?RegExMatch(text,"i)(\d{1,3})y(\d{1,2})m",age)第2行改这样比较好(不区分英文大小写)