[PA] 업무자동화/[AH]Autohotkey
AH 맨마지막 특정문자 찾기
Weneedu
2023. 2. 25. 03:15
20230224 1309
동기) 문자열에서 특정 문자가 여러 번 나올 경우 맨 마지막 위치를 찾고 싶다.
(예) 년월일 포맷에서 날짜만 뽑기
zstr:="2002-08-09"
ans:=InStr(zstr,"-",,0)
ans1:=StrLen(zstr)
zcount:=ans1-ans
StringMid, zoutput, zstr, ans+1, zcount+1
MsgBox,% ans ", " ans1 ", " zcount ", " zoutput
return
^ESC:: ExitApp
결과
(note) 파일 경로에서 파일 이름만 추출하고 싶다면 간단하게 SplitPath 함수를 쓰면 된다.
; https://www.autohotkey.com/docs/v1/lib/SplitPath.htm
ztmp:="c:\aaa\bbb\ccc.txt"
SplitPath, ztmp, zfile
MsgBox,% zfile
return
^ESC:: ExitApp
ExitApp