Code: Select all
Str := ComObject("Scriptlet.TypeLib").Guid
Msgbox StrLen(Str) ; 40
Msgbox StrSplit(Str).Length ; 38
What's the reason for this? Is it because of any hidden trimming operation performed?
Code: Select all
Str := ComObject("Scriptlet.TypeLib").Guid
Msgbox StrLen(Str) ; 40
Msgbox StrSplit(Str).Length ; 38
Code: Select all
#Requires AutoHotkey v2.0
#SingleInstance
Str := ComObject("Scriptlet.TypeLib").Guid
VarSetStrCapacity(&Str, -1)
MsgBox StrLen(Str) ; 38
SKAN wrote: ↑15 Aug 2023, 12:38
Seems like incorrect length!
Code: Select all
#Requires AutoHotkey v2.0 #SingleInstance Str := ComObject("Scriptlet.TypeLib").Guid VarSetStrCapacity(&Str, -1) MsgBox StrLen(Str) ; 38
Specify -1 for RequestedCapacity to update the variable's internally-stored string length to the length of its current contents. This is useful in cases where the string has been altered indirectly, such as by passing its address via DllCall or SendMessage. In this mode, VarSetStrCapacity returns the length rather than the capacity.
Code: Select all
❶ := ComObjCreate("Scriptlet.TypeLib").Guid
StringLower, ❷, ❶
❸ := SubStr(❷, 2, -1)
print_as_json([❶, StrLen(❶), ❷, StrLen(❷), ❸, StrLen(❸)])
Code: Select all
❶ := ComObject("Scriptlet.TypeLib").Guid
❷ := StrLower(❶)
❸ := SubStr(❷, 2, -1)
print_as_json([❶, StrLen(❶), ❷, StrLen(❷), ❸, StrLen(❸)])
20170201225639 wrote: ↑15 Aug 2023, 13:28when I then do SubStr(2,-1) to remove the brackets, I get the 36 character GUID.
Code: Select all
#Requires AutoHotkey v2.0
#SingleInstance
Str := ComObject("Scriptlet.TypeLib").Guid
Str := Trim(Str, "{}")
MsgBox StrLen(Str) "`n" Str ; 39
Str := ComObject("Scriptlet.TypeLib").Guid
VarSetStrCapacity(&Str, -1)
Str := Trim(Str, "{}")
MsgBox StrLen(Str) "`n" Str ; 36
Note: Due to reliance on null-termination, many built-in functions and most expression operators do not support strings with embedded null characters, and instead read only up to the first null character. However, basic manipulation of such strings is supported; e.g. concatenation, ==, !==, Chr(0), StrLen, SubStr, assignments, parameter values and return.
Source: Concepts and Conventions | AutoHotkey v2
I see. Noted.
Code: Select all
#Requires AutoHotkey v2.0
#SingleInstance
Str := ComObject("Scriptlet.TypeLib").Guid
DllCall("Shlwapi\StrTrimW", "str",Str, "str","{}")
MsgBox StrLen(Str) "`n" Str ; 36
20170201225639 wrote: ↑17 Aug 2023, 07:34What's a recommended way to reliably get rid of any potentially present embedded zeros from strings, preferably a way that works for both v1 and v2?
You aren't passing the string length to this API, only a pointer to a null-terminated string. The API doesn't trim null characters; it just doesn't consider them to be part of the string in the first place. If the string contains an embedded null character followed by some non-null characters, the latter will be lost as well.
It isn't quite accurate: DllCall doesn't know whether the function modifies the string; it updates the variable unconditionally. It is assumed that this update has no effect if the function didn't modify the string, but that isn't necessarily the case.If the called function modifies the string and the argument is a naked variable or VarRef, its contents will be updated.
Code: Select all
z := Chr(0)
MsgBox StrLen(z) ; 1
DllCall("MulDiv", "str", z, "int", 1, "int", 1)
MsgBox StrLen(z) ; 0
In other words, StrLen is correct and StrSplit is not (but I'd call it a known limitation, rather than a bug).Note: Due to reliance on null-termination, many built-in functions and most expression operators do not support strings with embedded null characters, and instead read only up to the first null character. However, basic manipulation of such strings is supported; e.g. concatenation, ==, !==, Chr(0), StrLen, SubStr, assignments, parameter values and return.
Source: Concepts and Conventions | AutoHotkey v2
Users browsing this forum: No registered users and 12 guests