RosettaCodeData/Task/Strip-comments-from-a-string/AutoHotkey/strip-comments-from-a-string.ahk
2023-07-01 13:44:08 -04:00

19 lines
546 B
AutoHotkey

Delims := "#;"
str := "apples, pears # and bananas"
str2:= "apples, pears, `; and bananas" ; needed to escape the ; since that is AHK's comment marker
msgbox % StripComments(Str,Delims)
msgbox % StripComments(Str2,Delims)
; The % forces expression mode.
StripComments(String1,Delims){
Loop, parse, delims
{
If Instr(String1,A_LoopField)
EndPosition := InStr(String1,A_LoopField) - 1
Else
EndPosition := StrLen(String1)
StringLeft, String1, String1, EndPosition
}
return String1
}