[AHK-] 7y8m 如何取出7,8 两个数字

楼主: 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."
作者: esouxcon   2023-01-26 13:42:00
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行改这样比较好(不区分英文大小写)
楼主: LPen (鸟人)   2023-01-28 08:15:00
可以,非常感谢.

Links booklink

Contact Us: admin [ a t ] ucptt.com