Here's an example, these things can be quite simple with arrays. I prepend a z to each key name, to avoid any interference with array methods.
Code: Select all
q:: ;mark duplicate lines (case insensitive)
vText := "a b c d e f a b c g h i a b c"
vText := StrReplace(vText, " ", "`n")
StrReplace(vText, "`n", "", vCount), vCount += 1
(oArray := {}).SetCapacity(vCount)
vSfx := "-extra"
vOutput := ""
VarSetCapacity(vOutput, StrLen(vText)*2)
Loop, Parse, vText, `n, `r
{
vTemp := A_LoopField
if oArray.HasKey("z" vTemp)
vOutput .= vTemp vSfx oArray["z" vTemp] "`r`n", oArray["z" vTemp] += 1
else
vOutput .= vTemp "`r`n", oArray["z" vTemp] := 1
}
MsgBox, % vOutput
vOutput2 := ""
for vKey, vValue in oArray
vOutput2 .= SubStr(vKey, 2) " " vValue "`r`n"
MsgBox, % vOutput2
oArray := ""
return
==================================================
A case sensitive version:
Code: Select all
q:: ;mark duplicate lines (case sensitive)
vText := "a b c d e f a b c g h i a b c"
vText := StrReplace(vText, " ", "`n")
StrReplace(vText, "`n", "", vCount), vCount += 1
oDict := ComObjCreate("Scripting.Dictionary")
vSfx := "-extra"
vOutput := ""
VarSetCapacity(vOutput, StrLen(vText)*2)
Loop, Parse, vText, `n, `r
{
vTemp := A_LoopField
if oDict.Exists("" vTemp)
vOutput .= vTemp vSfx oDict.Item("" vTemp) "`r`n", oDict.Item("" vTemp) += 1
else
vOutput .= vTemp "`r`n", oDict.Item("" vTemp) := 1
}
MsgBox, % vOutput
vOutput2 := ""
for vKey in oDict
vOutput2 .= vKey " " oDict.Item(vKey) "`r`n"
MsgBox, % vOutput2
oArray := ""
return