Copy part of text between ""

Get help with using AutoHotkey and its commands and hotkeys
hajen101
Posts: 2
Joined: 05 Jan 2021, 03:18

Copy part of text between ""

Post by hajen101 » 21 Jan 2021, 06:17

Can someone please help me with this problem. I have text lines like this that i want to copy. But only copy and paste "Two", then copy and paste "Three", and move on to "Four" copy and paste, then copy and paste "five", And when that is done it shall move on to the next line.

"one";"Two";"Three";"Four";"Five";"Six";"Seven";"Eight";"Nine";"Ten";"Eleven"
"one";"Two";"Three";"Four";"Five";"Six";"Seven";"Eight";"Nine";"Ten";"Eleven"
"one";"Two";"Three";"Four";"Five";"Six";"Seven";"Eight";"Nine";"Ten";"Eleven"
"one";"Two";"Three";"Four";"Five";"Six";"Seven";"Eight";"Nine";"Ten";"Eleven"
"one";"Two";"Three";"Four";"Five";"Six";"Seven";"Eight";"Nine";"Ten";"Eleven"
"one";"Two";"Three";"Four";"Five";"Six";"Seven";"Eight";"Nine";"Ten";"Eleven"
"one";"Two";"Three";"Four";"Five";"Six";"Seven";"Eight";"Nine";"Ten";"Eleven"

I know how to copy whole lines or text files but not just part of some txt

If someone knows how to do please respond

User avatar
mikeyww
Posts: 5335
Joined: 09 Sep 2014, 18:38

Re: Copy part of text between ""

Post by mikeyww » 21 Jan 2021, 06:40

Code: Select all

str =
(
"one";"Two";"Three"
"four";"five";"6"
)
item := StrSplit(StrReplace(str, "`n", ";"), ";")
F3::Send % StrReplace(item.RemoveAt(1), """")

garry
Posts: 2629
Joined: 22 Dec 2013, 12:50

Re: Copy part of text between ""

Post by garry » 21 Jan 2021, 07:26

@mikeyww your example works fine , maybe stop sending when finished
question : just copy a part from line and then continue next line ( e.g. two,three,five and then next line )

User avatar
mikeyww
Posts: 5335
Joined: 09 Sep 2014, 18:38

Re: Copy part of text between ""

Post by mikeyww » 21 Jan 2021, 07:57

Code: Select all

str =
(
"1one";"Two";"Three";"Four";"Five";"Six";"Seven";"Eight";"Nine";"Ten";"Eleven"
"2one";"Two";"Three";"Four";"Five";"Six";"Seven";"Eight";"Nine";"Ten";"Eleven"
)
item := []
Loop, Parse, str, `n 
 For k, v in StrSplit(RegExReplace(A_LoopField, "(.*?;){4}.*?\K;.*"), ";")
  item.Push(StrReplace(v, """"))
F3::
If !item.Count() {
 MsgBox, 48, Done, Nothing left!
 Return
}
SendInput % item.RemoveAt(1)
If !item.Count()
 MsgBox, 64, Success, Done!
Return

garry
Posts: 2629
Joined: 22 Dec 2013, 12:50

Re: Copy part of text between ""

Post by garry » 21 Jan 2021, 14:44

@mikeyww thank you , a last question :
example a csv file with 1000 rows and woul'd rearrange the columns ( 1,2,3,4,5,6,7,8,9,10 ) , new > show columns 8,6,4,9 ( or all columns with a different order / maybe I use another delimiter / make a new file )

User avatar
mikeyww
Posts: 5335
Joined: 09 Sep 2014, 18:38

Re: Copy part of text between ""

Post by mikeyww » 21 Jan 2021, 15:01

You could StrSplit or Loop, Parse the entire line, using ; as the delimiter, and then just use the parts that you want.

garry
Posts: 2629
Joined: 22 Dec 2013, 12:50

Re: Copy part of text between ""

Post by garry » 21 Jan 2021, 15:18

@mikeyww thank you , your solutions were always professional

hajen101
Posts: 2
Joined: 05 Jan 2021, 03:18

Re: Copy part of text between ""

Post by hajen101 » 22 Jan 2021, 03:30

Thanks i will try this later today :-)
The original part of lines look like this

* * * *
"1295058995";"1044721011064";"1909142087";"Glue";"26101";"48,00";"79,92";"99,9";"FRP";"FRP";"GL"

And the * is the parts i want to copy and paste into another program.
And i have a text file with multiply lines that looks like this :D

Thanks for all your help.

garry
Posts: 2629
Joined: 22 Dec 2013, 12:50

Re: Copy part of text between ""

Post by garry » 22 Jan 2021, 05:17

@hajen101 you want copy only some columns which is marked with '*' ( I didn't see marked columns , you mean the first 4 columns ? ) , mikeyww has above a script to see the first 5 columns
or , you mean you want the next row after the row * * * * ?
* * * *
"1295058995";"1044721011064";"1909142087";"Glue";"26101";"48,00";"79,92";"99,9";"FRP";"FRP";"GL"
And the * is the parts i want to copy and paste into another program.

User avatar
mikeyww
Posts: 5335
Joined: 09 Sep 2014, 18:38

Re: Copy part of text between ""

Post by mikeyww » 22 Jan 2021, 06:35

Here's an update for four values if you like.

Code: Select all

numberOfColumns := 4
str =
(
"1one";"Two";"Three";"Four";"Five";"Six";"Seven";"Eight";"Nine";"Ten";"Eleven"
"2one";"Two";"Three";"Four";"Five";"Six";"Seven";"Eight";"Nine";"Ten";"Eleven"
)
item := []
Loop, Parse, str, `n 
 For k, v in StrSplit(RegExReplace(A_LoopField, "(.*?;){" numberOfColumns - 1 "}.*?\K;.*"), ";")
  item.Push(StrReplace(v, """"))
F3::
If !item.Count() {
 MsgBox, 48, Done, Nothing left!
 Return
}
SendInput % item.RemoveAt(1)
If !item.Count()
 MsgBox, 64, Success, Done!
Return

Post Reply

Return to “Ask For Help”