[updated: 2019-08-22]
For this syntax character guide, please state any omissions, or make any comments.
See also:
jeeswg's RegEx tutorial (RegExMatch, RegExReplace) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=28031
jeeswg's strings tutorial - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=32985
==================================================
CHARACTERS THAT LOOK SIMILAR
Code: Select all
32 0020 SPACE
160 00A0 NO-BREAK SPACE
39 0027 ' APOSTROPHE
96 0060 ` GRAVE ACCENT
180 00B4 ´ ACUTE ACCENT
697 02B9 ʹ MODIFIER LETTER PRIME
8216 2018 ‘ LEFT SINGLE QUOTATION MARK [ANSI 145]
8217 2019 ’ RIGHT SINGLE QUOTATION MARK [ANSI 146]
34 0022 " QUOTATION MARK
8220 201C “ LEFT DOUBLE QUOTATION MARK [ANSI 147]
8221 201D ” RIGHT DOUBLE QUOTATION MARK [ANSI 148]
45 002D - HYPHEN-MINUS
173 00AD SOFT HYPHEN
8211 2013 – EN DASH [ANSI 150]
8722 2212 − MINUS SIGN
8212 2014 — EM DASH [ANSI 151]
9644 25AC ▬ BLACK RECTANGLE
183 00B7 · MIDDLE DOT
8226 2022 • BULLET [ANSI 149]
176 00B0 ° DEGREE SIGN
186 00BA º MASCULINE ORDINAL INDICATOR
8304 2070 ⁰ SUPERSCRIPT ZERO
8728 2218 ∘ RING OPERATOR
9675 25CB ○ WHITE CIRCLE
9702 25E6 ◦ WHITE BULLET
216 00D8 Ø LATIN CAPITAL LETTER O WITH STROKE
8709 2205 ∅ EMPTY SET
47 002F / SOLIDUS
8260 2044 ⁄ FRACTION SLASH
58 003A : COLON
1475 05C3 ׃ HEBREW PUNCTUATION SOF PASUQ
181 00B5 µ MICRO SIGN
956 03BC μ GREEK SMALL LETTER MU
955 03BB λ GREEK SMALL LETTER LAMDA
8257 2041 ⁁ CARET INSERTION POINT
8908 22CC ⋌ RIGHT SEMIDIRECT PRODUCT
46 002E . FULL STOP
8230 2026 … HORIZONTAL ELLIPSIS [ANSI 133]
35 0023 # NUMBER SIGN
9839 266F ♯ MUSIC SHARP SIGN
98 0062 b LATIN SMALL LETTER B
9837 266D ♭ MUSIC FLAT SIGN
OPERATOR PRECEDENCE
Variables and Expressions
https://autohotkey.com/docs/Variables.htm#Operators
Expression Operators (in descending precedence order)
%Expr%
x.y [note: x.y (obj.key)]
new
++ --
**
- ! ~ & * [note: - (unary minus), & (address), * (dereference)]
* / // [note: * (multiply)]
+ - [note: - (subtract)]
<< >>
& ^ | [note: & (bitwise-and)]
. [note: . (concatenate)]
~=
> < >= <=
= == <> != !==
IS IN CONTAINS
NOT
AND &&
OR ||
?: [note: ?: (ternary operator)]
:= += -= *= /= //= .= |= &= ^= >>= <<=
=> [note: () => expr (fat arrow function)]
, [note: , (multi-statement)]
operators with two meanings:
. concatenate/obj.key [concatenate is redundant, you can omit the .]
- subtract/unary minus [virtually the same meaning]
& address/bitwise-and
* multiply/dereference
bitwise operators v. logical operators:
& bitwise-and, && AND
^ bitwise-exclusive-or (xor)
| bitwise-or, || OR
~ bitwise-not, ! NOT [note: '!' and 'NOT' have different precedences]
note: a mnemonic for precedence: AXiOm (and/xor/or)
note: AHK v1 only: * (dereference), <>
note: AHK v2 only: => (fat arrow function), !==
note: AHK v1/v2 differences
!= (AHK v1): case sensitivity depends on A_StringCaseSense on/off/locale
!= (AHK v2): case insensitive (insensitivity mode depends on A_StringCaseSense off/locale)
==================================================
OPERATOR SUMMARY
mathematical:
++ -- **
-[unary] ~
* / // + - << >> & ^ |
+= -= *= /= //= |= &= ^= >>= <<=
general:
%Expr% x.y new ! &[address] *[deref] .[concatenate] ~=
> < >= <= = == <> != !==
IS IN CONTAINS
NOT AND && OR ||
?: := .= => ,
==================================================
AUTOHOTKEY SYNTAX: CHARACTER GUIDE
[ANSI (CP-1252) 32-255]
!"#$%&'()*+,-./0123456789:;<=>?
@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_
`abcdefghijklmnopqrstuvwxyz{|}~
€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ
¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿
ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞß
àáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ
(note: ANSI CP-1252 characters 128-159, differ from Unicode characters 128-159)
==================================================
[USEFUL LINK]
Variables and Expressions
https://autohotkey.com/docs/Variables.htm#Operators
[ASCII CHARACTERS 33-126 MINUS LETTERS/DIGITS][126-32-52-10=32]
!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
! NOT, (SendInput: alt)
" assign text
# directives, (SendInput: win)
$ (hotkeys: hook)
% variable dereference (command style), variable double-dereference (expression style), function names, force an expression (warning: not mod)
& address, bitwise-and, && AND
' assign text (AHK v2)
( continuation section, if-statements, functions, object methods
) continuation section, if-statements, functions, object methods
* multiply, dereference, variadic function calls(/used in objects), DllCall (pointers), ** powers, /* comment block start, */ comment block end, (hotkeys: wildcard: ignore modifiers)
+ add, ++ increment, (SendInput: shift)
, (warning: not decimal point), delimiter, multi-statement
- subtract, -- decrement
. decimal point, concatenate, objects
/ divide, // floor divide, /* comment block start, */ comment block end
: ?: ternary operator
; comments (comment flag)
< less than, << bit shift left, <> not equal to
= [SEE EQUALS SECTIONS AT BOTTOM]
> greater than, >> bit shift right, <> not equal to
? ?: ternary operator
@
[ define array, object member access
\
] define array, object member access
^ (warning: not powers), bitwise-exclusive-or, (SendInput: ctrl)
_
` escape character
{ code blocks, define object, (SendInput), (Format)
| bitwise-or, GUI parameters, || OR
} code blocks, define object,(SendInput), (Format)
~ bitwise-not, (hotkeys: native)
==================================================
[EQUALS]
:= assign
+= add
-= subtract
*= multiply
/= divide
//= floor divide
.= append
|= bitwise-or
&= bitwise-and
^= bitwise-exclusive-or
>>= bit shift right
<<= bit shift left
[EQUALS][FURTHER USES]
= assign, compare case insensitive
== compare case sensitive
~= RegExMatch
>= greater than or equal to
<= less than or equal to
!= not equal to
!== not equal to (AHK v2)
=> fat-arrow function (AHK v2)
==================================================
[FURTHER USES]
!
" paths (command line parameters), (invalid filename character)
# url fragment identifier, (issue with WB object Navigate)
$
% paths (environment variables), URI
& menu item text
' (Excel VBA single-line comments)
(
)
* FileAppend, Ptr* (PtrP), loop files wildcard, (invalid filename character)
+
, paths (command line parameters+)
-
. (invalid filename character+)
/ (invalid filename character), paths (command line parameters+), // C++ single-line comments
: (invalid filename character)
; ini files (comments)
< (invalid filename character)
= ini files
> (invalid filename character)
? (invalid filename character)
@ email address, reg files (default registry value)
[ ini files (section header)
\ (invalid filename character)
] ini files (section header)
^
_
`
{ CLSIDs
| (invalid filename character), || GuiControl
} CLSIDs
~
==================================================
[CHARACTERS THAT SOMETIMES REQUIRE ESCAPING]
! SendInput
" expression style
# SendInput
$
% command style, expression style (AHK v2)
& InputBox
' expression style (AHK v2)
(
) continuation section
*
+ SendInput
, command style, if var contains, if var in
-
.
/
:
; command style, expression style, hotkeys, IniWrite
<
= IniWrite
>
?
@
[ IniWrite
\
]
^ SendInput
_
` command style, expression style, (SendInput/hotstrings)
{ SendInput
|
} SendInput
~
==================================================
[CHARACTERS THAT SOMETIMES REQUIRE ESCAPING]
SendInput: {+} {^} {#} {!} {{} {}} ``
Format: {{} {}}
general: ` ; % "
general (AHK v2): '
commands: ,
if var in/contains: ,
continuation sections: )
InputBox: &
ini files (IniWrite): = [ ;
[RegEx] 12 characters that need escaping in RegEx generally:
not brackets (8): \ .*?+ | ^$
open brackets (3): [ { (
close brackets (1): )
[RegEx] 4 characters that need escaping in a RegEx character class:
^ - ] \
;RegEx escape characters:
;12 characters that need escaping in RegEx generally: \.*?+[{|()^$
;4 characters that need escaping in a RegEx character class: ^-]\
;RegEx: note: \x22 [double quote]
;#EscapeChar - Syntax & Usage | AutoHotkey
;https://autohotkey.com/docs/commands/_EscapeChar.htm
;escape characters in AutoHotkey expressions:
;`` `a `b `f `n `r `t `v
;`; [needed when ; is preceded by a space/tab]
;"" [AHK v1]
;`" [AHK v2]
==================================================
INVALID FILENAME CHARACTERS
invalid filename characters (in a name without a path) (9):
\ / : * ? " < > |
invalid filename characters (in a full path) (7):
/ * ? " < > |
note: chars 1-31 are also invalid dir/name characters
note: file names (minus dirs) cannot start/end in .
Excel VBA type-declaration characters:
integer %, long &, currency @, single !, double #, string $
==================================================
HOTKEYS
In all the hotkey labels (not hotstrings) I use I found the following 22 characters
other than space and the 62 alnum: !#$&'*+,-./:;<=>[\]^`~
They are all from the 'classic 32' (my coinage): !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
special characters (11): : & +^#! $~* <>
normal keys (11): ',-./;=[\]`
from the classic 32 chars not in list (10): "%()?@_{|}
(special + normal): #
Note: hash hotkey: '#::', win+hash hotkey: '##::', win hotkey: 'LWin::' or 'RWin::'
Note: semicolon hotkey: '`;::' or 'SC027::', ctrl+semicolon hotkey: '^;::' or '^SC027::'
Note: AltGr hotkey: 'RAlt', AltGr+t: 'RAlt & t' or '<^>!t'
==================================================
HOTSTRINGS
;certain hotstrings with colon may not work:
:c*:i-::I- ;a hotstring that works
:c*:i:::I: ;doesn't work
==================================================
ANSI (CP-1252) CHARACTERS (VERBATIM) (WYSIWYG) (CONTINUATION SECTIONS)
Code: Select all
;AHK v1 command style
;ANSI (CP-1252) 32-255 verbatim
vOutput = ;continuation section
(% ` Join`r`n
!"#$%&'()*+,-./0123456789:;<=>?
@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_
`abcdefghijklmnopqrstuvwxyz{|}~
€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ
¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿
ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞß
àáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ
)
;AHK v1 expression style
;ANSI (CP-1252) 32-255 verbatim except double quote
vOutput := " ;continuation section
(` Join`r`n
!""#$%&'()*+,-./0123456789:;<=>?
@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_
`abcdefghijklmnopqrstuvwxyz{|}~
€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ
¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿
ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞß
àáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ
)"
;AHK v2
;ANSI (CP-1252) 32-255 verbatim
vOutput := " ;continuation section
(` Join`r`n
!"#$%&'()*+,-./0123456789:;<=>?
@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_
`abcdefghijklmnopqrstuvwxyz{|}~
€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ
¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿
ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞß
àáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ
)"
PREPARE TEXT FOR STORING IN A VARIABLE
Code: Select all
q:: ;prepare text for storing in a variable
vText := ""
Loop, 255
vText .= Chr(A_Index)
vText := StrReplace(vText, "``", "````")
vText := StrReplace(vText, "`r", "``r")
vText := StrReplace(vText, "`n", "``n")
if !!SubStr(1,0) ;vIsV1
vText := StrReplace(vText, Chr(34), Chr(34) Chr(34))
else
vText := StrReplace(vText, Chr(34), "``" Chr(34))
Clipboard := "var := " Chr(34) vText Chr(34)
return
LIST UNICODE CHARACTERS 1-65535
Code: Select all
vOutput := ""
VarSetCapacity(vOutput, 100000*2)
Loop, 65535
{
if (Mod(A_Index, 32) = 31)
vOutput .= Chr(A_Index) "`r`n"
else
vOutput .= Chr(A_Index)
}
Clipboard := vOutput
MsgBox, % "done"
return
UNICODE CHARACTERS GET NAMES
Code: Select all
q:: ;Unicode character get name (same method as Character Map)
vPath := "C:\Windows\System32\getuname.dll"
hModule := DllCall("LoadLibrary", Str,vPath)
vChar := "!"
vNum := Asc(vChar)
VarSetCapacity(vName, 1024)
DllCall("LoadString", Ptr,hModule, UInt,vNum, Str,vName, Int,1024)
MsgBox, % vName
VarSetCapacity(vOutput, 1000000*2)
Loop, 65536
{
VarSetCapacity(vName, 1024)
DllCall("LoadString", Ptr,hModule, UInt,A_Index-1, Str,vName, Int,1024)
vOutput .= (A_Index-1) "`t" vName "`r`n"
}
Clipboard := vOutput
MsgBox, % vOutput
DllCall("FreeLibrary", Ptr,hModule)
return
NamesList.txt
http://www.unicode.org/Public/UNIDATA/NamesList.txt
==================================================
ANSI AND UNICODE CHARACTERS (STRGET AND STRPUT)
Code: Select all
;get 255 ANSI characters (in AHK Unicode versions)
vText := ""
VarSetCapacity(vText, 255, 0)
Loop, 255
NumPut(A_Index, vText, A_Index-1, "UChar")
vOutput := StrGet(&vText, 255, "CP0")
MsgBox, % Clipboard := "[" vOutput "]"
;square root sign, Chr(8730) (UTF-8 bytes) (in AHK Unicode versions)
vUTF16 := Chr(8730)
vSize := StrPut(vUTF16, "UTF-8")
vUTF8 := ""
VarSetCapacity(vUTF8, vSize, 0)
StrPut(vUTF16, &vUTF8, "UTF-8")
vOutput := StrGet(&vUTF8, vSize, "UTF-8")
MsgBox, % vOutput
return
LIST EVERY CHARACTER THAT APPEARS IN A STRING
[ list all characters that appear in a string]
[ list unique characters]
Tip: use a MsgBox with a variable enclosed in square brackets (or some other characters), to check for leading/trailing whitespace.
Code: Select all
vText := " abc "
MsgBox, % "[" vText "]"
Code: Select all
q:: ;list characters in string
;vText := JEE_GetSelectedText()
vText := Clipboard
vText := StrReplace(vText, Chr(1), "", vContainsChr1)
vContainsChr1 := !!vContainsChr1
vOutput := ""
VarSetCapacity(vOutput, 1000000*2)
while !(vText = "")
{
vOrd := Ord(vText)
vText := StrReplace(vText, Chr(vOrd))
vOutput .= Format("{:07}", vOrd) "`t" Chr(vOrd) Chr(1)
if (A_Index > 300)
MsgBox, % vOrd " " Chr(vOrd) "`r`n" vText
}
Sort, vOutput, % "D" Chr(1)
vOutput := StrReplace(vOutput, Chr(1), "`r`n")
if vContainsChr1
vOutput := Format("{:07}", 1) "`t" Chr(1) "`r`n" vOutput
Clipboard := vOutput
MsgBox, % "done"
return
w:: ;list characters in string (simple)
vText := "abcde `t`r`n"
vOutput := ""
Loop, Parse, vText
vOutput .= Ord(A_LoopField) "`t" A_LoopField "`r`n"
Clipboard := vOutput
MsgBox, % vOutput
return
GET LETTERS IN KEYBOARD ORDER (E.G. 'QWERTY' ORDER)
Code: Select all
q:: ;get letters in keyboard order (e.g. 'qwerty' order)
VarSetCapacity(vOutput, 26*2)
Loop, 256
if !((vText := GetKeyName(Format("sc{:x}", A_Index-1))) = "")
&& (StrLen(vText) = 1) && RegExMatch(vText, "[A-Za-z]")
vOutput .= vText
MsgBox, % Format("{:L}", vOutput) ;qwertyuiopasdfghjklzxcvbnm
return
w:: ;get letters in keyboard order (e.g. 'qwerty' order)
VarSetCapacity(vOutput, 26*2)
VarSetCapacity(vText, 256)
Loop, 256
if DllCall("user32\GetKeyNameText", Int,(A_Index-1)<<16, Str,vText, Int,256)
&& (StrLen(vText) = 1) && RegExMatch(vText, "[A-Za-z]")
vOutput .= vText
MsgBox, % Format("{:L}", vOutput) ;qwertyuiopasdfghjklzxcvbnm
return
RECREATE AHK'S ORD/CHR FUNCTIONS
Code: Select all
q:: ;recreate Ord function (AHK Unicode only)
MsgBox, % JEE_Ord(Chr(8730))
Loop, 1114111
{
vChar := Chr(A_Index)
if !(JEE_Ord(vChar) = Ord(vChar))
MsgBox, % "mismatch: " JEE_Ord(vChar) "`r`n" Ord(vChar)
}
MsgBox, % "done"
return
w:: ;recreate Chr function (AHK Unicode only)
MsgBox, % JEE_Chr(8730)
Loop, 1114111
{
if !(JEE_Chr(A_Index) = Chr(A_Index))
MsgBox, % "mismatch: " A_Index "`r`n" JEE_Chr(vChar) "`r`n" Chr(vChar)
}
MsgBox, % "done"
return
;==================================================
JEE_Ord(vText)
{
local vLen,vNum1,vNum2
vLen := StrLen(vText)
vNum1 := (vLen>0) ? NumGet(&vText, 0, "UShort") : 0
vNum2 := (vLen>1) ? NumGet(&vText, 2, "UShort") : 0
if (vNum1 >= 0xD800) && (vNum1 <= 0xDBFF)
&& (vNum2 >= 0xDC00) && (vNum2 <= 0xDFFF)
return ((vNum1-0xD800)<<10)+(vNum2-0xDC00)+0x10000
else
return vNum1
}
;==================================================
JEE_Chr(vNum)
{
local vText
VarSetCapacity(vText, 6, 0)
if (vNum + 0 = "") || (vNum < 0) || (vNum > 0x10FFFF)
return
else if (vNum >= 0x10000)
{
vNum -= 0x10000
NumPut(0xD800+((vNum >> 10) & 0x3FF), &vText, 0, "UShort")
NumPut(0xDC00+(vNum & 0x3FF), &vText, 2, "UShort")
}
else
NumPut(vNum, &vText, 0, "UShort")
VarSetCapacity(vText, -1)
return vText
}
FORMAT FUNCTION EXAMPLES
- Each {} / {:f} / {n} / {n:f} contains text based on the parameters, the rest of the text is literal text.
- {n:f}, n is a parameter number, f is a format.
Code: Select all
;hex2dec (hexadecimal to decimal)
MsgBox, % Format("{:i}", "0x" 10) ;16
;dec2hex (decimal to hexadecimal)
MsgBox, % Format("{:X}", 65535) ;FFFF
MsgBox, % Format("{:x}", 65535) ;ffff
MsgBox, % Format("0x{:X}", 65535) ;0xFFFF (recommended)
MsgBox, % Format("0x{:x}", 65535) ;0xffff (recommended)
MsgBox, % Format("{:#X}", 65535) ;0XFFFF
MsgBox, % Format("{:#x}", 65535) ;0xffff
MsgBox, % Format("0x{:02X}{:02X}{:02X}", 10, 11, 12) ;0x0A0B0C
MsgBox, % Format("0x{:02X}{:02X}{:02X}", 0xAA, 0xBB, 0xCC) ;0xAABBCC
;rounding/truncating
MsgBox, % Format("{:0.3f}", 2/3) ;0.667
MsgBox, % Format("{:0.4f}", 2/3) ;0.6667
MsgBox, % Format("{:i}", 2/3) ;0
MsgBox, % Format("{:i}", 123.1) ;123
MsgBox, % Format("{:i}", 123.9) ;123
MsgBox, % Format("{:i}", -123.1) ;-123
MsgBox, % Format("{:i}", -123.9) ;-123
;padding (leading zeros)
MsgBox, % Format("{:01}", "") ;0
MsgBox, % Format("{:02}", 3) ;03
MsgBox, % Format("{:04}", 15) ;0015
MsgBox, % Format("{:04X}", 15) ;000F
MsgBox, % Format("0x{:06X}", 15) ;0x00000F
MsgBox, % Format("0x{:08X}", 15) ;0x0000000F
;trailing and leading padding at the same time
;note: I use '4.4' to mean '0000.0000'
MsgBox, % Format("{:09.4f}", 12.34) ;0012.3400 ;'4.4' or '3.4' if negative
MsgBox, % Format("{:010.4f}", -12.34) ;-0012.3400
MsgBox, % Format("{:011.6f}", 12.34) ;0012.340000 ;'4.6' or '3.6' if negative
MsgBox, % Format("{:012.6f}", -12.34) ;-0012.340000
MsgBox, % Format("{:013.6f}", 12.34) ;000012.340000 ;'6.6' or '5.6' if negative
MsgBox, % Format("{:014.6f}", -12.34) ;-000012.340000
;change case
MsgBox, % Format("{:U}", "HeLLo") ;HELLO
MsgBox, % Format("{:T}", "HeLLo") ;Hello
MsgBox, % Format("{:L}", "HeLLo") ;hello
;repeat string n times / padding (spaces/leading zeros)
MsgBox, % Format("{:5}", "") ;(5 spaces)
MsgBox, % Format("{:05}", 0) ;00000
MsgBox, % StrReplace(Format("{:5}", ""), " ", "a") ;aaaaa
MsgBox, % StrReplace(Format("{:5}", ""), " ", "a_") ;a_a_a_a_a_
MsgBox, % "[" Format("{:6}", "abc") "]" ;pad with spaces to the left
MsgBox, % "[" Format("{:-6}", "abc") "]" ;pad with spaces to the right
MsgBox, % "[" Format("{:06}", "abc") "]" ;pad with zeros to the left
;MsgBox, % "[" Format("{:-06}", "abc") "]" ;pad with zeros to the right (doesn't work)
;date/time
vYear := 2006, vMonth := 5, vDay := 4, vHour := 3, vMin := 2, vSec := 1
MsgBox, % Format("{:04}{:02}{:02}", vYear, vMonth, vDay) ;yyyyMMdd
MsgBox, % Format("{:04}{:02}{:02}{:02}{:02}{:02}", vYear, vMonth, vDay, vHour, vMin, vSec) ;yyyyMMddHHmmss
MsgBox, % Format("{:02}/{:02}/{:04}", vDay, vMonth, vYear) ;dd/MM/yyyy
MsgBox, % Format("{:02}/{:02}/{:04}", vMonth, vDay, vYear) ;MM/dd/yyyy
MsgBox, % Format("{:02}:{:02}:{:02}", vHour, vMin, vSec) ;HH:mm:ss
MsgBox, % Format("{:04}{:02}{:02}", 2006, 5, 4) ;20060504
MsgBox, % Format("{:04}{:02}{:02}{:02}{:02}{:02}", 2006, 5, 4, 3, 2, 1) ;20060504030201
MsgBox, % Format("{:02}/{:02}/{:04}", 4, 5, 2006) ;04/05/2006
MsgBox, % Format("{:02}:{:02}:{:02}", 3, 2, 1) ;03:02:01
;convert seconds to d h m s
vSec := 86400*4 + 3600*3 + 60*2 + 1 ;4d 3h 2m 1s
MsgBox, % Format("{}d {}h {}m {}s", vSec//86400, Mod(vSec, 86400)//3600, Mod(vSec, 3600)//60, Mod(vSec, 60)) ;4d 3h 2m 1s
MsgBox, % Format("{} day{} + {:02}:{:02}:{:02}", vSec//86400, (vSec//86400=1)?"":"s", Mod(vSec, 86400)//3600, Mod(vSec, 3600)//60, Mod(vSec, 60)) ;4 days + 03:02:01
;concatenation
MsgBox, % Format("x{} y{} w{} h{}", 1, 2, 3, 4) ;x1 y2 w3 h4
MsgBox, % Format("{},{},{}", "a", "b", "c") ;a,b,c
MsgBox, % Format("{}-{}-{}", "a", "b", "c") ;a-b-c
MsgBox, % Format("{}`r`n{}`r`n{}", "a", "b", "c") ;a CRLF b CRLF c
MsgBox, % Format("path: {}`r`nname: {}", "C:\MyDir\MyFile.txt", "MyFile.txt")
;alternative to Chr
;note: Chr(0) and Format("{:c}", 0) are both blank in AHK v1, but contain a null char in AHK v2
;note: Format only works like Chr() for Chr(0) to Chr(65535)
;note: Format("{:c}", n) is equivalent to Chr(Mod(n, 65536))
MsgBox, % Format("{:c}{:c}{:c}{:c}{:c}", 97, 98, 99, 100, 101) ;abcde
MsgBox, % Chr(97) Chr(98) Chr(99) Chr(100) Chr(101) ;abcde
;==================================================
;further examples
MsgBox, % Format("{} {} {}", "a", "b", "c") ;a b c
MsgBox, % Format("{1} {2} {3}", "a", "b", "c") ;a b c
MsgBox, % Format("{3} {2} {1}", "a", "b", "c") ;c b a
MsgBox, % Format("{1:} {2:} {3:}", "a", "b", "c") ;a b c
MsgBox, % Format("{3:} {2:} {1:}", "a", "b", "c") ;c b a
MsgBox, % Format("{X} {X} {X}", 10, 11, 12) ;{X} {X} {X} (doesn't work)
MsgBox, % Format("{:X} {:X} {:X}", 10, 11, 12) ;A B C
MsgBox, % Format("{1:X} {2:X} {3:X}", 10, 11, 12) ;A B C
MsgBox, % Format("{3:X} {2:X} {1:X}", 10, 11, 12) ;C B A
- what a stunning cast of characters -