看板 EzHotKey 關於我們 聯絡資訊
我最近遇到要處理 年齡的字串,我覺得我的寫法很冗長, 不知道有沒有更簡潔的寫法,比方用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." -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 175.98.20.173 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/EzHotKey/M.1674682430.A.957.html
esouxcon: text:="7y8m" 01/26 13:42
esouxcon: RegExMatch(text,"(\d{1,3})y(\d{1,2})m",age) 01/26 13:42
esouxcon: Msgbox The age is %age1% years %age2% month old 01/26 13:42
esouxcon: 安捏? 01/26 13:42
esouxcon: RegExMatch(text,"i)(\d{1,3})y(\d{1,2})m",age) 01/26 14:00
esouxcon: 第2行改這樣比較好(不區分英文大小寫) 01/26 14:00
LPen: 可以,非常感謝. 01/28 08:15