Data Extraction Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
vSky
Posts: 80
Joined: 30 May 2022, 10:13

Data Extraction

Post by vSky » 05 Aug 2022, 18:57

N Süre Süre
001 ‭‭33‬%‬ ‭‭36‬%‬ ‭‭35‬%‬ 5:03:09 ‭‭22‬%‬ 11:01:24
002 ‭‭56‬%‬ ‭‭59‬%‬ ‭‭51‬%‬ 14:43:49 ‭‭86‬%‬ 0:35:40
003 ‭‭34‬%‬ ‭‭23‬%‬ ‭‭17‬%‬ 5:04:10 ‭‭74‬%‬ 3:39:32
005 ‭‭8‬%‬ ‭‭8‬%‬ ‭‭7‬%‬ 13:00:50 ‭‭60‬%‬ 1:27:43
006 ‭‭19‬%‬ ‭‭19‬%‬ ‭‭19‬%‬ 335:35:11 ‭‭20‬%‬ 18:10:00
004 ‭‭44‬%‬ ‭‭69‬%‬ ‭‭53‬%‬ 2:49:24 ‭‭53‬%‬ 7:57:21
007 ‭‭67‬%‬ ‭‭61‬%‬ ‭‭74‬%‬ 2:46:20 ‭‭86‬%‬ 0:49:14


How can I extract this listed text?

Code: Select all

StringSplit, word_array, GetList, %A_Space%, . ;
I tried to get the data one by one in this way, but it didn't work.

AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: Data Extraction

Post by AHKStudent » 05 Aug 2022, 19:04

Code: Select all

test :=
(
"001 ‭‭33‬%‬ ‭‭36‬%‬ ‭‭35‬%‬ 5:03:09 ‭‭22‬%‬ 11:01:24
002 ‭‭56‬%‬ ‭‭59‬%‬ ‭‭51‬%‬ 14:43:49 ‭‭86‬%‬ 0:35:40
003 ‭‭34‬%‬ ‭‭23‬%‬ ‭‭17‬%‬ 5:04:10 ‭‭74‬%‬ 3:39:32
005 ‭‭8‬%‬ ‭‭8‬%‬ ‭‭7‬%‬ 13:00:50 ‭‭60‬%‬ 1:27:43
006 ‭‭19‬%‬ ‭‭19‬%‬ ‭‭19‬%‬ 335:35:11 ‭‭20‬%‬ 18:10:00
004 ‭‭44‬%‬ ‭‭69‬%‬ ‭‭53‬%‬ 2:49:24 ‭‭53‬%‬ 7:57:21
007 ‭‭67‬%‬ ‭‭61‬%‬ ‭‭74‬%‬ 2:46:20 ‭‭86‬%‬ 0:49:14"
)
array := StrSplit(test,[A_Space, "`n"])
for k, v in array
	MsgBox, % v
ExitApp

User avatar
vSky
Posts: 80
Joined: 30 May 2022, 10:13

Re: Data Extraction

Post by vSky » 05 Aug 2022, 19:20

AHKStudent wrote:
05 Aug 2022, 19:04

Code: Select all

test :=
(
"001 ‭‭33‬%‬ ‭‭36‬%‬ ‭‭35‬%‬ 5:03:09 ‭‭22‬%‬ 11:01:24
002 ‭‭56‬%‬ ‭‭59‬%‬ ‭‭51‬%‬ 14:43:49 ‭‭86‬%‬ 0:35:40
003 ‭‭34‬%‬ ‭‭23‬%‬ ‭‭17‬%‬ 5:04:10 ‭‭74‬%‬ 3:39:32
005 ‭‭8‬%‬ ‭‭8‬%‬ ‭‭7‬%‬ 13:00:50 ‭‭60‬%‬ 1:27:43
006 ‭‭19‬%‬ ‭‭19‬%‬ ‭‭19‬%‬ 335:35:11 ‭‭20‬%‬ 18:10:00
004 ‭‭44‬%‬ ‭‭69‬%‬ ‭‭53‬%‬ 2:49:24 ‭‭53‬%‬ 7:57:21
007 ‭‭67‬%‬ ‭‭61‬%‬ ‭‭74‬%‬ 2:46:20 ‭‭86‬%‬ 0:49:14"
)
array := StrSplit(test,[A_Space, "`n"])
for k, v in array
	MsgBox, % v
ExitApp
I can do this with a FileReadLine I want the columns to be read.

User avatar
boiler
Posts: 16769
Joined: 21 Dec 2014, 02:44

Re: Data Extraction

Post by boiler » 05 Aug 2022, 21:53

You certainly haven't made it clear what you are looking to get if AHKStudent's solution isn't what you want.

User avatar
vSky
Posts: 80
Joined: 30 May 2022, 10:13

Re: Data Extraction

Post by vSky » 05 Aug 2022, 23:48

boiler wrote:
05 Aug 2022, 21:53
You certainly haven't made it clear what you are looking to get if AHKStudent's solution isn't what you want.
The list has sequential data. I need to introduce all of this data to variables.

User avatar
vSky
Posts: 80
Joined: 30 May 2022, 10:13

Re: Data Extraction

Post by vSky » 06 Aug 2022, 00:07

boiler wrote:
05 Aug 2022, 21:53
You certainly haven't made it clear what you are looking to get if AHKStudent's solution isn't what you want.
I checked it again after you said it. I don't think there are any spaces between the letters. That's why it creates problems when adding commas. Is there a method for me to remove this?
Attachments
Screenshot_5.png
Screenshot_5.png (23.76 KiB) Viewed 1501 times

User avatar
boiler
Posts: 16769
Joined: 21 Dec 2014, 02:44

Re: Data Extraction

Post by boiler » 06 Aug 2022, 00:20

So now it’s a different problem. At first, you didn’t understand that AHKStudent’s code did exactly what you asked. You didn’t realize it was reading each piece of data into an array element because you assumed you understand what his code was doing and didn’t bother running it, correct?

And now you’re saying the issue is that the original data contains hidden characters?

AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: Data Extraction

Post by AHKStudent » 06 Aug 2022, 00:22

vSky wrote:
05 Aug 2022, 23:48
boiler wrote:
05 Aug 2022, 21:53
You certainly haven't made it clear what you are looking to get if AHKStudent's solution isn't what you want.
The list has sequential data. I need to introduce all of this data to variables.
the StrSplit function creates an array, you can access them uniquely using array[1] array[2] etc you can use those like a variable

Code: Select all

test :=
(
"001 ‭‭33‬%‬ ‭‭36‬%‬ ‭‭35‬%‬ 5:03:09 ‭‭22‬%‬ 11:01:24
002 ‭‭56‬%‬ ‭‭59‬%‬ ‭‭51‬%‬ 14:43:49 ‭‭86‬%‬ 0:35:40
003 ‭‭34‬%‬ ‭‭23‬%‬ ‭‭17‬%‬ 5:04:10 ‭‭74‬%‬ 3:39:32
005 ‭‭8‬%‬ ‭‭8‬%‬ ‭‭7‬%‬ 13:00:50 ‭‭60‬%‬ 1:27:43
006 ‭‭19‬%‬ ‭‭19‬%‬ ‭‭19‬%‬ 335:35:11 ‭‭20‬%‬ 18:10:00
004 ‭‭44‬%‬ ‭‭69‬%‬ ‭‭53‬%‬ 2:49:24 ‭‭53‬%‬ 7:57:21
007 ‭‭67‬%‬ ‭‭61‬%‬ ‭‭74‬%‬ 2:46:20 ‭‭86‬%‬ 0:49:14"
)
array := StrSplit(test,[A_Space, "`n"])
loop, % array.length()
	MsgBox, % array[a_index]
ExitApp

User avatar
vSky
Posts: 80
Joined: 30 May 2022, 10:13

Re: Data Extraction

Post by vSky » 06 Aug 2022, 00:53

boiler wrote:
06 Aug 2022, 00:20
So now it’s a different problem. At first, you didn’t understand that AHKStudent’s code did exactly what you asked. You didn’t realize it was reading each piece of data into an array element because you assumed you understand what his code was doing and didn’t bother running it, correct?

And now you’re saying the issue is that the original data contains hidden characters?
No, on the contrary, because I tried it, I realized that it was a different problem. There are hidden characters in the data I received. I'm posting a picture of it. Since there are hidden characters, the code you gave works like this.
Attachments
Screenshot_6.png
Screenshot_6.png (31.23 KiB) Viewed 1355 times

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Data Extraction

Post by BoBo » 06 Aug 2022, 01:54

This (whole) thread might help: viewtopic.php?p=273414#p273414 :think:

User avatar
boiler
Posts: 16769
Joined: 21 Dec 2014, 02:44

Re: Data Extraction  Topic is solved

Post by boiler » 06 Aug 2022, 02:10

Below is your actual text, which we can get by quoting your original post, which is why you shouldn't post it directly without putting it into a codebox.

Code: Select all

N				Süre		Süre
001	‭‭33‬%‬	‭‭36‬%‬	‭‭35‬%‬	5:03:09	‭‭22‬%‬	11:01:24
002	‭‭56‬%‬	‭‭59‬%‬	‭‭51‬%‬	14:43:49	‭‭86‬%‬	0:35:40
003	‭‭34‬%‬	‭‭23‬%‬	‭‭17‬%‬	5:04:10	‭‭74‬%‬	3:39:32
005	‭‭8‬%‬	‭‭8‬%‬	‭‭7‬%‬	13:00:50	‭‭60‬%‬	1:27:43
006	‭‭19‬%‬	‭‭19‬%‬	‭‭19‬%‬	335:35:11	‭‭20‬%‬	18:10:00
004	‭‭44‬%‬	‭‭69‬%‬	‭‭53‬%‬	2:49:24	‭‭53‬%‬	7:57:21
007	‭‭67‬%‬	‭‭61‬%‬	‭‭74‬%‬	2:46:20	‭‭86‬%‬	0:49:14

It does not have spaces like your post would indicate (without quoting it to get the raw text), so you would split on tab and linefeed characters. You can also replace the non-ASCII characters with a RegExReplace, like below.

Code: Select all

test := "
(
N				Süre		Süre
001	‭‭33‬%‬	‭‭36‬%‬	‭‭35‬%‬	5:03:09	‭‭22‬%‬	11:01:24
002	‭‭56‬%‬	‭‭59‬%‬	‭‭51‬%‬	14:43:49	‭‭86‬%‬	0:35:40
003	‭‭34‬%‬	‭‭23‬%‬	‭‭17‬%‬	5:04:10	‭‭74‬%‬	3:39:32
005	‭‭8‬%‬	‭‭8‬%‬	‭‭7‬%‬	13:00:50	‭‭60‬%‬	1:27:43
006	‭‭19‬%‬	‭‭19‬%‬	‭‭19‬%‬	335:35:11	‭‭20‬%‬	18:10:00
004	‭‭44‬%‬	‭‭69‬%‬	‭‭53‬%‬	2:49:24	‭‭53‬%‬	7:57:21
007	‭‭67‬%‬	‭‭61‬%‬	‭‭74‬%‬	2:46:20	‭‭86‬%‬	0:49:14
)"
test := RegExReplace(test, "[^[:ascii:]]")
array := StrSplit(test,[A_Tab, "`n"])
loop, % array.length()
	MsgBox, % array[a_index]

User avatar
rommmcek
Posts: 1470
Joined: 15 Aug 2014, 15:18

Re: Data Extraction

Post by rommmcek » 06 Aug 2022, 02:57

boiler wrote:
06 Aug 2022, 02:10
..., which we can get by quoting your original post, ...
Awesome observation & RegEx solution!

Addendum: "Visualizing" hidden characters by pasting data into an ANSI editor.

Code: Select all

N				Süre		Süre
001	??33?%?	??36?%?	??35?%?	5:03:09	??22?%?	11:01:24
002	??56?%?	??59?%?	??51?%?	14:43:49	??86?%?	0:35:40
003	??34?%?	??23?%?	??17?%?	5:04:10	??74?%?	3:39:32
005	??8?%?	??8?%?	??7?%?	13:00:50	??60?%?	1:27:43
006	??19?%?	??19?%?	??19?%?	335:35:11	??20?%?	18:10:00
004	??44?%?	??69?%?	??53?%?	2:49:24	??53?%?	7:57:21
007	??67?%?	??61?%?	??74?%?	2:46:20	??86?%?	0:49:14

User avatar
vSky
Posts: 80
Joined: 30 May 2022, 10:13

Re: Data Extraction

Post by vSky » 07 Aug 2022, 18:32

AHKStudent wrote:
06 Aug 2022, 00:22
vSky wrote:
05 Aug 2022, 23:48
boiler wrote:
05 Aug 2022, 21:53
You certainly haven't made it clear what you are looking to get if AHKStudent's solution isn't what you want.
The list has sequential data. I need to introduce all of this data to variables.
the StrSplit function creates an array, you can access them uniquely using array[1] array[2] etc you can use those like a variable
Yes, this method you provided works the way I want it to. I couldn't run it correctly because of the hidden character problem. @boiler I was able to solve the problem thanks to the ASCII method it gave. It's working as I want it now. Thank you.

Post Reply

Return to “Ask for Help (v1)”