Dear All,
I have a text file that is updated everyday. ( eg. test.txt )
The text file has just two columns A and B
Actually, I hope the data in the column A should be in the column B vice versa. ( column A data to column B vice versa column B data to column A )
column A | column B
0 | aaaaa
0 | bbbbb
0 | ccccc
1 | ddddd
1 | eeeee
0 | ffffff
----->
aaaaa | 0
bbbbb | 0
ccccc | 0
ddddd | 1
eeeee | 1
fffff | 0
I really appreciate you all who help me
how to change the column A with the column B in Text file? Topic is solved
Re: how to change the column A with the column B in Text file? Topic is solved
Read the lines into a variable. Parse the lines in an outer loop and split each line in an inner loop using the pipe character (probably need to removes spaces first), the write each line with the parts swapped to a new file as you go.
Re: how to change the column A with the column B in Text file?
Dear Boiler,boiler wrote:Read the lines into a variable. Parse the lines in an outer loop and split each line in an inner loop using the pipe character (probably need to removes spaces first), the write each line with the parts swapped to a new file as you go.
Thank you for your answer.
I could resolve this problem based on your idea.
Really thank you for your idea again.!
Re: how to change the column A with the column B in Text file?
Classic problem.
Here's some example code (*assuming 2 columns only* of course):
Here's some example code (*assuming 2 columns only* of course):
Code: Select all
q::
vText = ;continuation section
(Join`r`n
0 | aaaaa
0 | bbbbb
0 | ccccc
1 | ddddd
1 | eeeee
0 | fffff
)
vOutput := ""
VarSetCapacity(vOutput, StrLen(vText)*2)
vText := StrReplace(vText, "`r`n", "`n")
Loop, Parse, vText, `n
{
vTemp := A_LoopField
vTemp := StrReplace(vTemp, " | ", "|")
;method 1
oTemp := StrSplit(A_LoopField, "|")
vOutput .= oTemp.2 " | " oTemp.1 "`r`n"
;method 2
;StringSplit, vTemp, vTemp, |
;vOutput .= vTemp2 " | " vTemp1 "`r`n"
;method 3
;Loop, Parse, vTemp, |
;vTemp%A_Index% := A_LoopField
;vOutput .= vTemp2 " | " vTemp1 "`r`n"
}
oTemp := ""
vOutput := SubStr(vOutput, 1, -2)
Clipboard := vOutput
MsgBox, % "done"
return
Last edited by jeeswg on 11 Jun 2017, 19:21, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
- SpeedMaster
- Posts: 494
- Joined: 12 Nov 2016, 16:09
Re: how to change the column A with the column B in Text file?
Here is another way with 2d array. Any better idea ?
Code: Select all
text_in=
(
column A | column B
0 | aaaaa
0 | bbbbb
0 | ccccc
1 | ddddd
1 | eeeee
0 | ffffff
)
msgbox, % "TEXT IN" . "`n" . text_in
rows:=StrSplit(text_in,"`n")
Array:=[]
for k, row in rows
if row contains |
loop, parse, row, "|"
{
if a_index=1
a:=a_loopfield
if a_index=2
{
b:=a_loopfield
row:= % b . " | " . a
}
Array[k]:=StrSplit(row, "|")
}
else
Array[k]:=StrSplit(row, "|")
;msgbox, % st_printarr(array)
; recombine array into string
for l, rows in Array
{
for m, col in rows
str.= col " |"
str.="`n"
}
TEXT_OUT:=str
TEXT_OUT:=RegExReplace(TEXT_OUT, "\|`n", "`n")
MsgBox, % "TEXT OUT `n" . TEXT_OUT