作者:
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行改這樣比較好(不區分英文大小寫)