One of my favorite languages treated strings as an array and could do the following (the "=" in that language is ":=" in AHK and "!" is the rest of line comment initiator):
myString = "This is my test string."
Char3 = myString[3] ! Char3 = "i"
Char7 = myString[7] ! Char7 = "s"
Chars3to7 = myString[3 : 7] ! Chars3to7 = "is is"
It did not do the following, which I would have liked:
CharsStartingAt3size5 := myString[3 # 5] ! CharsStartingAt3size5 = "is is"
Of course, you usually used variables in place of the numbers.
You could also do this:
myString[3] = "a" ! myString = "Thas is my test string."
myString[4] = "t" ! myString = "That is my test string."
myString[6 : 10] = "was a" ! myString = "That was a test string."
It did not do the following, which I would have liked:
myString[3 # 8] = "ere's my" ! myString = "There's my test string."
The above was a tremendous time saving syntax. It has the SubStr function as well to access characters within the string, and, of course, you could concatenate strings together to change the string, but the above syntax was so much simpler and quicker.
Sorry, though I have time to make a suggestion, I don't have time for an ongoing conversation about my suggestion!
This is my one and only post to this thread.
This is the "Wish List", this is my wish.
Strings as arrays
Re: Strings as arrays
You can use commands/StringSplit.htm and commands/SubStr.htm for this.
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
Re: Strings as arrays
Just for reference:
Sinkfaze comes pretty close to this wish https://autohotkey.com/board/topic/5456 ... ipulation/
and you have TF & stringthings https://github.com/ahkscript/awesome-Au ... nipulation
Sinkfaze comes pretty close to this wish https://autohotkey.com/board/topic/5456 ... ipulation/
and you have TF & stringthings https://github.com/ahkscript/awesome-Au ... nipulation
Re: Strings as arrays
nice, I didn't know about that PythonStr library that sinkfaze createdGuest wrote:Just for reference:
Sinkfaze comes pretty close to this wish https://autohotkey.com/board/topic/5456 ... ipulation/
Re: Strings as arrays
Don't forget to checkout the link in the post beneath sinkfaze by jethrow https://autohotkey.com/board/topic/4670 ... ies-ahk-l/
Re: Strings as arrays
StrSplit() can be used to convert a string into an array of characters. But it won't permit myString[3 : 7].
Re: Strings as arrays
It's a minor convenience (syntax sugar) over simply using SubStr, but SubStr is less obscure for the uninitiated.
Code: Select all
myString := "This is my test string."
Char3 := myString[3] ; Char3 := "i"
Char7 := myString[7] ; Char7 := "s"
Chars3to7 := myString[3,,7] ; Chars3to7 := "is is"
CharsStartingAt3size5 := myString[3, 5] ; CharsStartingAt3size5 = "is is"
ListVars
Pause
StrIndex(s, i, n:="", j:="") {
static _ := ("".base.__Get := Func("StrIndex"))
return n="" ? j="" ? SubStr(s,i,1) : SubStr(s,i,j-i+1) : SubStr(s,i,n)
}
Re: Strings as arrays
Wow!
What just happened?!
What just happened?!
My scripts:-
XRef - Produces Cross Reference lists for scripts
ReClip - A Text Reformatting and Clip Management utility
ScriptGuard - Protects Compiled Scripts from Decompilation
I also maintain Ahk2Exe
XRef - Produces Cross Reference lists for scripts
ReClip - A Text Reformatting and Clip Management utility
ScriptGuard - Protects Compiled Scripts from Decompilation
I also maintain Ahk2Exe
Re: Strings as arrays
Interesting ... I never really played around this.lexikos wrote:https://autohotkey.com/docs/Objects.htm ... ase_Object
Edit*
Code: Select all
; ##############################################################################################################################################################
; EXAMPLE
; ##############################################################################################################################################################
; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
; NEW
; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Str := "This is my test string."
; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
; GET
; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
MsgBox % Str ; This is my test string.
MsgBox % Str[] ; This is my test string.
MsgBox % Str[7] ; s
MsgBox % Str[17, 7] ; string.
MsgBox % Str[0] ; 23 (length)
MsgBox % Str.Length ; 23 (length)
; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
; CALL
; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
MsgBox % Str.Compare("This is my test string.") ; 1 (TRUE, CaseSensitive = 0)
MsgBox % Str.Compare("This is my test strinG.") ; 1 (TRUE, CaseSensitive = 0)
MsgBox % Str.Compare("This is my test strinG.", 1) ; 0 (FALSE, CaseSensitive = 1)
MsgBox % Str.InStr("my") ; 9
; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
; SET
; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Str[] := "This is my new test string."
MsgBox % Str ; This is my new test string.
Str[3] := 1
MsgBox % Str ; Th1s is my new test string.
Str[12, 3] := "NEW"
MsgBox % Str ; Th1s is my NEW test string.
; ##############################################################################################################################################################
; DEFAULT BASE OBJECT
; ##############################################################################################################################################################
__DefaultBaseObject() {
static _ := ("".base.base := {__Get: Func("__DefaultBaseObject__Get"), __Set: Func("__DefaultBaseObject__Set"), __Call: Func("__DefaultBaseObject__Call")})
}
; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
; GET
; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
__DefaultBaseObject__Get(Var, Param*) {
;X := Var[]
if (!Param.MaxIndex())
return (Var)
;X := Var[0] | X := Var.Length
else if (Param[1] = 0 || Param[1] = "Length")
return (StrLen(Var))
;X := Var[X], / X != 0
return (Param[2] = "" ? (Param[3] = "" ? SubStr(Var, Param[1], 1) : SubStr(Var, Param[1], Param[3] - Param[1] + 1)) : SubStr(Var, Param[1], Param[2]))
}
; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
; SET
; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
__DefaultBaseObject__Set(ByRef Var, Param*) {
;Var[] := X
if (Param.MaxIndex() = 1)
Var := Param[1]
;Var[X1] := X2
else if (Param.MaxIndex() = 2)
Var := SubStr(Var, 1, Param[1] - 1) . Param[2] . SubStr(Var, Param[1] + 1)
;Var[X1, X2] := X3
else if (Param.MaxIndex() = 3)
Var := SubStr(Var, 1, Param[1] - 1) . Param[3] . SubStr(Var, Param[1] + Param[2])
return (0)
}
; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
; CALL
; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
__DefaultBaseObject__Call(Var, FuncName, Param*) {
;bool Compare(Var, CaseSensitive?)
if (FuncName = "Compare")
return (Param[2] ? (Var == Param[1]) : (Var = Param[1]))
;int InStr(Needle, CaseSensitive?, StartingPos=1, Occurrence=1)
else if (FuncName = "InStr")
return InStr(Var, Param[1], !!Param[2], Param[3] = "" ? 1 : Param[3], Param[4] = "" ? 1 : Param[4])
}
I could replace a character doing this:
Code: Select all
Str := "This is my test string."
Pos := 3
Replace := "1"
NumPut(Ord(Replace), Str, (Pos - 1) * 2, "Uchar")
MsgBox % Str
Code: Select all
Str := "This is my test string."
Pos := 3
Replace := "•"
NumPut(Ord(Replace), Str, (Pos - 1) * 2, "Uchar")
MsgBox % Str
Re: Strings as arrays
Code: Select all
Str := "This is my test string."
Pos := 3
Replace := "•"
NumPut(Ord(Replace), Str, (Pos - 1) * 2, A_IsUnicode?"USHORT":"UCHAR")
MsgBox % Str
Re: Strings as arrays
I normally don't like youtube videos but noone explains it better than this guy does:
Recommends AHK Studio
Re: Strings as arrays
I must pay more attention .HotKeyIt wrote:Code: Select all
Str := "This is my test string." Pos := 3 Replace := "•" NumPut(Ord(Replace), Str, (Pos - 1) * 2, A_IsUnicode?"USHORT":"UCHAR") MsgBox % Str
Thanks HotKeyIt.
Re: Strings as arrays
Haha, I have not ignored you, it seems that the video you have posted does not appear to me, but I have already extracted the URL. I had to activate the subtitles to understand what he is saying (my English is medium).nnnik wrote:Please don't ignore me
I've seen other vídeos too. Thanks nnnik .
Re: Strings as arrays
Great video! I didn't know much about UTF8, now I do.
[AHK] 1.1.23.05 x32 Unicode
[WIN] 10 Pro x64 Version 5111 (Build 10586.218)
[WIN] 10 Pro x64 Version 5111 (Build 10586.218)
Who is online
Users browsing this forum: -Garfle- and 41 guests