Code: Select all
1 2 3
1 2 3
1 2 3
What is the simplest way to rearrange such that we have one column like:
Code: Select all
1
1
1
2
2
2
3
3
3
Tried but failing ;(
Thank you
Code: Select all
1 2 3
1 2 3
1 2 3
Code: Select all
1
1
1
2
2
2
3
3
3
Code: Select all
Loop, Parse, Clipboard, `r`n
{
Line := A_LoopField
Loop, Parse, Line, %A_Tab%
Column%A_Index% .= A_LoopField "`r`n"
}
Clipboard =
While, Column%A_Index%
Clipboard .= Column%A_Index%
MsgBox, %Clipboard%
Code: Select all
clipboard =
(
1 2 3
1 2 3
1 2 3
)
Array := Object()
Loop, Parse, Clipboard, %A_Tab%
Array.Insert([ A_LoopField ])
for j, e in Array
{
for k, e in Array[j]
column .= Array[j, k] . "`n"
}
Sort, column, N
column := RTrim(column, "`n")
MsgBox, %column%
Code: Select all
StringReplace, var, Clipboard, `t, `n, All
Sort, var
clipboard := var
Code: Select all
clipboard=
(
1 2 3
1 2 3
1 2 3
)
msgbox, % "input:" . "`n" . clipboard
col:=0 row:=0
loop, parse, clipboard, "`n"
{
row:=row+1
line:=a_loopfield
loop, parse, line
{
if a_loopfield is integer
{
col:=col+1
var%col% .=a_loopfield . "`r`n"
}
}
col:=0
}
loop, % row
{
output .= var%a_index%
}
msgbox, % "output:" . "`n" . output
clipboard:=output
exitapp
return
Code: Select all
q:: ;columns to column
vText := " ;continuation section
(
a d g
b e h
c f i
)"
oArray := []
Loop, Parse, vText, `n, `r
Loop, Parse, A_LoopField, `t
if oArray.HasKey(A_Index)
oArray[A_Index] .= A_LoopField "`n"
else
oArray[A_Index] := A_LoopField "`n"
vOutput := ""
VarSetCapacity(vOutput, StrLen(vText)*2+2)
Loop, % oArray.Length()
vOutput .= oArray[A_Index]
MsgBox, % vOutput
return
Code: Select all
test =
(
Train 23 Dog
Plane 22 Cat
Car 21 Fish
)
MsgBox,, StackCols, % StackCols(test)
StackCols(Str)
{
Cols := {} , Rows := StrSplit(Str,"`n")
Loop % Rows.Length()
Cols[A_Index] := StrSplit(Rows[A_Index],A_Tab)
Loop % Rows.Length()
Loop % Cols[i:=A_Index].Length()
Out .= Cols[A_Index,i] . "`n"
return SubStr(Out,1,-1)
}
Code: Select all
clipboard := "1 2 3`n1 4 3`n1 2 3"
for i, row in StrSplit(clipboard, "`n")
for n, col in StrSplit(row, "`t")
(!isobject(table))?(table := Object(), table[n] := col "`n" table[n]):(table[n] := col "`n" table[n])
for key, val in table
(A_index=1)?(clipboard := val):(clipboard .= val)
msgbox % clipboard
Actually you sorted all the column members, which wasn't what I wanted, but thanks for trying it was close.GEV wrote:This should also work:
Code: Select all
Clipboard =
(
a d g
b e h
c f i
)
MsgBox, % ToString(Split(Clipboard))
Split(Str) {
obj := Object()
for i, row in StrSplit(Str, "`n") {
for j, val in StrSplit(row, "`t") {
if(!obj[j]) {
obj[j] := Object()
}
obj[j].Push(val)
}
}
return obj
}
ToString(obj) {
for i, col in obj {
for j, val in col {
str .= val "`n"
}
if(i < obj.Length()) {
str .= "----------------`n"
}
}
return str
}
Code: Select all
Clipboard =
(
a d g
b e h
c f i
)
MsgBox, % ToString(Split(Clipboard))
Split(Str) {
obj := Object()
for i, row in StrSplit(StrReplace(str, "`r`n", "`n"), "`n") {
obj.Push(StrSplit(row, "`t"))
}
return obj
}
ToString(obj) {
strlst := Object()
for i, row in obj {
for j, col in row {
strlst[j] .= col "`n"
}
}
for i, v in strlst {
str .= v (i < strlst.Length() ? "----------------`n" : "")
}
return str
}
Code: Select all
Clipboard =
(
Countries Capitals Population Language
USA Washington D.C. 309 million English
Sweden Stockholm 9 million Swedish
)
MsgBox, % ToString(Split(Clipboard))
Clipboard =
(
Countries,Capitals,Population,Language;
USA,Washington D.C.,309 million,English;
Sweden,Stockholm,9 million,Swedish;
)
MsgBox, % ToString(Split(Clipboard, ";", ","))
Clipboard := "Countries,Capitals,Population,Language;USA,Washington D.C.,309 million,English;Sweden,Stockholm,9 million,Swedish;"
MsgBox, % ToString(Split(Clipboard, ";", ","))
Split(Str, rowdel := "`n", coldel := "`t") {
obj := Object()
str := StrReplace(str, "`r`n", "`n")
if(rowdel != "`n") {
str := StrReplace(str, rowdel "`n", rowdel)
}
for i, row in StrSplit(str, rowdel) {
obj.Push(StrSplit(row, coldel))
}
return obj
}
ToString(obj) {
strlst := Object()
for i, row in obj {
for j, col in row {
strlst[j] .= col "`n"
}
}
for i, v in strlst {
str .= v (i < strlst.Length() ? "----------------`n" : "")
}
return str
}