Xavier > 2025-10-03 20:05
/* Here Are Two Examples */
;---------------------------------------------------------------------------
/* # 1 starts and end with %...% signs */
original clip =
%regpath%`n`nthis Reg key cannot be read. it like doesn't exist.`n`n A_IsRegkey=%A_IsRegKey%
encoded =
regpath . "`n`nthis Reg key cannot be read. it like doesn't exist.`n`n A_IsRegkey=" . A_IsRegKey
fixed := " . regpath . "`n`nthis Reg key cannot be read. it like doesn't exist.`n`n A_IsRegkey=" . A_IsRegKey . "
usage =
Tip(" .regpath . "`n`nthis Reg key cannot be read. it like doesn't exist.`n`n A_IsRegkey=" . A_IsRegKey . ", 4000)
; or..
Tip(fixed, 4000)
;---------------------------------------------------------------------------
/* # 2 starts with a word (that quote is correct) and end with % (missing its closing fullstop quote) */
; if the strings starts with a \w , wordboundry, and end with a % it would need a full stop double-quote at the end, example #2
original clip =
Failed to copy directory:`n%filetoclip% to %destfolder%\%lastfolder%`n`nERR. Line#: %A_LineNumber%`nin %A_linefile%
encoded =
"Failed to copy directory:`n" . filetoclip . " to " . destfolder . "\" . lastfolder . "`n`nERR. Line#: " . A_LineNumber . "`nin " . A_linefile
fixed := "Failed to copy directory:`n" . filetoclip . " to " . destfolder . "\" . lastfolder . "`n`nERR. Line#: " . A_LineNumber . "`nin " . A_linefile .""
usage =
Box("Failed to copy directory:`n" . filetoclip . " to " . destfolder . "\" . lastfolder . "`n`nERR. Line#: " . A_LineNumber . "`nin " . A_linefile ."", 5)
; or...
Box(fixed, 5)
returnXavier > 2025-10-03 22:08

;===========================================================================
;===========================================================================
;===========================================================================
; Convert legacy %var% syntax to expression syntax ("text" . var . "text")
LegacyToExpression(input) {
if (input = "")
return """"""
; Check if starts/ends with variable
startsWithVar := (SubStr(input, 1, 1) = "%")
endsWithVar := (SubStr(input, 0) = "%")
result := ""
parts := []
current := ""
inVar := false
; Parse into parts (variables and text)
i := 1
while (i <= StrLen(input)) {
char := SubStr(input, i, 1)
nextChar := SubStr(input, i+1, 1)
; Handle escaped percent `%
if (char = "``" && nextChar = "%") {
current .= "%"
i += 2
continue
}
; Handle % delimiter
if (char = "%") {
if (inVar) {
; End variable
parts.Push({type: "var", value: current})
current := ""
inVar := false
} else {
; Start variable - save text first
if (current != "")
parts.Push({type: "text", value: current})
current := ""
inVar := true
}
i++
continue
}
current .= char
i++
}
; Add remaining text
if (current != "")
parts.Push({type: inVar ? "var" : "text", value: current})
; Build expression from parts
for index, part in parts {
if (index > 1)
result .= " . "
if (part.type = "var")
result .= part.value
else
result .= """" . part.value . """"
}
; Handle wrapping based on start/end
if (startsWithVar && endsWithVar) {
; Starts AND ends with variable: "" . var . "text" . var . ""
result := """" . """" . " . " . result . " . " . """" . """"
}
else if (startsWithVar && !endsWithVar) {
; Starts with variable, ends with text: "" . var . "text"
result := """" . """" . " . " . result
}
else if (!startsWithVar && endsWithVar) {
; Starts with text, ends with variable: "text" . var . ""
result .= " . " . """" . """"
}
; else: starts and ends with text - no wrapping needed
return result
}
; Convert expression syntax to legacy %var% syntax
ExpressionToLegacy(input) {
if (input = "")
return ""
; Remove quotes and concatenation operators
result := input
; Pattern: "text" . var . "text" -> text%var%text
; Remove " . and . "
result := RegExReplace(result, "\s*\.\s*", "§§§") ; Temp marker for dots
result := StrReplace(result, """", "") ; Remove all quotes
; Split by temp markers and rebuild with %
parts := StrSplit(result, "§§§")
result := ""
for index, part in parts {
part := Trim(part)
if (part = "")
continue
; If it looks like a variable name (alphanumeric, no spaces)
if (RegExMatch(part, "^[a-zA-Z_][a-zA-Z0-9_]*$"))
result .= "%" . part . "%"
else
result .= part
}
return result
}
; Simple wrapper for clipboard
ConvertClipboard(direction := "ToExpression") {
if (direction = "ToExpression")
clipboard := LegacyToExpression(clipboard)
else if (direction = "ToLegacy")
clipboard := ExpressionToLegacy(clipboard)
ToolTip, Converted!
; SetTimer, RemoveToolTip, -1000
sleep 1000
tooltip
return
}
; Example hotkeys (optional - remove if not needed)
; ^!1::ConvertClipboard("ToExpression") ; Ctrl+Alt+1 - Convert clipboard to expression
; ^!2::ConvertClipboard("ToLegacy") ; Ctrl+Alt+2 - Convert clipboard to legacy
/*
USAGE EXAMPLES:
; Test the functions directly:
test1 := LegacyToExpression("Hello %name% you are %age%")
MsgBox, %test1% ; Shows: "Hello " . name . " you are " . age
test2 := LegacyToExpression("%var%")
MsgBox, %test2% ; Shows: var
test3 := LegacyToExpression("%var% text")
MsgBox, %test3% ; Shows: var . " text"
test4 := LegacyToExpression("text %var%")
MsgBox, %test4% ; Shows: "text " . var
; Convert clipboard:
clipboard := "Hello %name%!"
ConvertClipboard("ToExpression")
MsgBox, %clipboard% ; Shows: "Hello " . name . "!"
; Or call directly:
myVar := "Hello %world%"
converted := LegacyToExpression(myVar)
MsgBox, %converted%
*/
; Example hotkeys (optional - remove if not needed)
;; commented out my own funcs so you should be able to run this.
^!1:: ;; test key
CovertVartoExpAHK:
; iflive()
send ^c
sleep 200
ConvertClipboard("ToExpression") ; Ctrl+Alt+1 - Convert clipboard to expression
sleep 200
Send ^v
; sleep 200
; restoreclipboard()
return
^!2:: ;; test key
CovertVartoExpAHKputinBox:
; iflive()
send, ^c
sleep 200
ConvertClipboard("ToExpression") ; Ctrl+Alt+1 - Convert clipboard to expression
sleep 200
clipboard := "Box(" . Clipboard . ", 4)"
Send ^v
; sleep 200
; restoreclipboard()
return
coversiontest8: using the 2nd hotkey above ^!2
; starting\copied text = %A_linefile% is have a fit @ line#: %A_linenumber%
Tip("" . A_linefile . " is a have a fit @ line#: " . A_linenumber . "", 4000)
return
/*
I also got this working with lines that start\or\end with word with mixed %% and the start\or\end
eg...
; starts with word, ends with %
line# %A_linenumber% is having a fit in %A_linefile%
Tip("line# " . A_linenumber . " is having a fit in " . A_linefile . "", 3000)
and
; starts with % , ends with word
%a_linefile% @ Line# %A_linenumber% is having a fit!
Tip("" . a_linefile . " @ Line# " . A_linenumber . " is having a fit!", 3000)
; starts and ends with %%
%A_linefile% is have a fit @ line#: %A_linenumber%
Tip("" . A_linefile . " is have a fit @ line#: " . A_linenumber . "", 3000)
*/
tip(msg, rtt := 0) { ;; fucnction ;; tip() rtt := timeOut in millisecs. eg, 3000 = 3 seconds
if (rtt > 0)
{
Tooltip, %msg%
SetTimer, RemoveTooltip, %rtt%
}
else
Tooltip, %msg%
}
~esc::
RemoveToolTip:
tooltip
returnJean Lalonde > 2025-10-05 09:49
original
%regpath%`n`nthis Reg key cannot be read. it like doesn't exist.`n`n A_IsRegkey=%A_IsRegKey%
encoded =
regpath . "`n`nthis Reg key cannot be read. it like doesn't exist.`n`n A_IsRegkey=" . A_IsRegKeyregpath := "TEST"
MsgBox, % regpath . "`n`nthis Reg key cannot be read. it like doesn't exist.`n`n A_IsRegkey=" . A_IsRegKeyXavier > 2025-10-06 10:22
Jean Lalonde > 2025-10-06 11:32