StrSplit not splitting? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
PepeLapiu
Posts: 324
Joined: 19 Jun 2020, 14:06

Re: StrSplit not splitting?

Post by PepeLapiu » 02 Jan 2022, 18:43

Okay, so I almost got it working. If only you guys and the puter would just listen to me and do what I tell you to do, we would all get along a little better. :D
Here is pasted my clipboard on the X between the two O's like this -----> OXO
O
Status for contract n49iegSVo3RsJsce changed from pending to canceled

Please check your notifications page for details

O
And here is the code that just won't listen to me:

Code: Select all

array[1] = null                 ;making sure I don't recycle and old clipboard
array[3] = null                 ;I use null instead of "" because those produce an annoying warning every time I run the script
array[8] = null

Haystack := clipboard
MsgBox, % Haystack       
Array := StrSplit(Haystack, [A_Space,"`n","`l","`r"]) 

MsgBox, % "Status: " array[1]            ;shows nothing or empty space
MsgBox, % "contract: " array[3]         ;shows nothing or empty space
MsgBox, % "to: " array[8]                   ;shows [changed] instead of [to]

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

Re: StrSplit not splitting?

Post by boiler » 02 Jan 2022, 18:50

PepeLapiu wrote:

Code: Select all

array[3] = null                 ;I use null instead of "" because those produce an annoying warning every time
You comment doesn’t make sense. If you get a warning, it would be for using an initialized variable like null, not "". Your problem is you did not yet learn the difference between the legacy assignment operator = and expression assignment operator :=.

PepeLapiu
Posts: 324
Joined: 19 Jun 2020, 14:06

Re: StrSplit not splitting?

Post by PepeLapiu » 02 Jan 2022, 19:10

boiler wrote:
02 Jan 2022, 18:50
PepeLapiu wrote:

Code: Select all

array[3] = null                 ;I use null instead of "" because those produce an annoying warning every time
You comment doesn’t make sense. If you get a warning, it would be for using an initialized variable like null, not "". Your problem is you did not yet learn the difference between the legacy assignment operator = and expression assignment operator :=.
Var = null seems to work just fine. But Var = "" and Var := "" both produce an annoying warning that the variable doesn't have an assigned value. It works this way, It works with the "" too, but with warning interuption.

So what about my array? Why isn't it working?

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

Re: StrSplit not splitting?

Post by boiler » 02 Jan 2022, 19:17

PepeLapiu wrote: Var = null seems to work just fine.
Only "works" if you're comparing it to a particular value like 1, since 1 is not equal to null. But it is assuredly not an empty/null variable. So if you want to continue operate under that misconception as you continue coding, you will run into troubles that you won't understand.

PepeLapiu wrote: But Var = "" and Var := "" both produce an annoying warning that the variable doesn't have an assigned value. It works this way, It works with the "" too, but with warning interuption.
No, doesn't make sense that Var := "" would produce that warning. You did something else to cause the warning. Here's proof:

Code: Select all

#Warn
Var := ""
MsgBox, % Var

PepeLapiu wrote: So what about my array? Why isn't it working?
Do I really have to mention := a third time?

User avatar
flyingDman
Posts: 2817
Joined: 29 Sep 2013, 19:01

Re: StrSplit not splitting?

Post by flyingDman » 02 Jan 2022, 19:25

PepeLapiu wrote:
02 Jan 2022, 10:29
...for 2 days to no avail. Until I figured out it should be StrSplit() and not StrSplit_() with a space.
Time to open the help file! If you had looked up strsplit() here https://www.autohotkey.com/docs/commands/StrSplit.htm and tried the 2 examples, it would not not have taken you 2 days, but 2 minutes.
PepeLapiu wrote:
02 Jan 2022, 10:29
And at times it just confused me more than anything else when you try fix what"s not broke while completely ignoring what is broken.
What is that all about? Nobody is trying to mislead or misguide you here. All comments made are to the point. It is up to you to put all those suggestions together and fix your script. If you expect someone to rewrite your script, correct all mistakes, and present you a fully functioning script on a silver platter, you're hugely mistaken about what the forum is all about...

Re: array[1] = null. Not only does this make no sense, it is wrong. array has not been defined yet. You can't assign a value to any element yet. If you put #warn at the top of your script (as suggested by @boiler) , you'll see the error. (and btw it does not make any difference whether it is null or ""). Also. what is `l ???.
And btw your script gives me the expected results...
14.3 & 1.3.7

PepeLapiu
Posts: 324
Joined: 19 Jun 2020, 14:06

Re: StrSplit not splitting?

Post by PepeLapiu » 02 Jan 2022, 19:44

flyingDman wrote:
02 Jan 2022, 19:25
What is that all about? Nobody is trying to mislead or misguide you here. All comments made are to the point. It is up to you to put all those suggestions together and fix your script. If you expect someone to rewrite your script, correct all mistakes, and present you a fully functioning script on a silver platter, you're hugely mistaken about what the forum is all about...
Not claiming anyone is trying to mislead or misguide me. I was simply venting out my frustration after trying to research, rearrange, and redo my variables over and over for two days, often introducing more errors into my script when all I likely needed to do is change StrSplit () to StrSplit(), None of that had anything to do with none of you. Nobody here told me to put a freaking space between StrSplit and ()
Somehow I get the feeling my poor english with my bad attempts at jokes are rubbing you guys the wrong way. So no more trying to be funny for me, And if something offends you, it's very likely you understand me wrong or I wrote it wrong, I swear I mean no offence to anyone here.

About the script, I'll post full results in next post,

PepeLapiu
Posts: 324
Joined: 19 Jun 2020, 14:06

Re: StrSplit not splitting?

Post by PepeLapiu » 02 Jan 2022, 20:16

Okay. So here is my latest attempt at it with included a screengrab of both Message boxes.

Code: Select all

Haystack := clipboard
MsgBox, % Haystack      
Array := StrSplit(Haystack, [A_Space,"`n","`l","`r"]) 

MsgBox, % "Start" "`n" array[1] "`n" array[2] "`n" array[3] "`n" array[4] "`n" array[5] "`n" array[6] "`n" array[7] "`n" array[8] "`n" array[9] "`n" array[10] array[11] "`n" array[12] "`n" array[13] "`n" array[14] "`n" array[15] "`n" array[16] "`n" array[17] "`n" array[18] "`n" array[19] "`n" array[20] array[21] "`n" array[22] "`n" array[23] "`n" array[24] "`n" array[25] "`n" array[26] "`n" "Stop"
Image
Image

Now, it appears to be removing all the L's but not the N's and R's. And it's fusing together the number and the BTC sign.
So what stupid little mistake did I make this time that's causing all this stuff?

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

Re: StrSplit not splitting?

Post by boiler » 02 Jan 2022, 20:23

It is removing L characters because you have `l in your list of characters to split the string by, and that is not an escape sequence. It is therefore treating it as a regular L character. The characters by which the string is split do not appear in the resulting elements, hence they are removed. As flyingDman asked, what is that meant to to represent? Are you aware of what the `n and `r represent?

Can you post the copied text into a code box so we can see what special characters it might contain?

PepeLapiu
Posts: 324
Joined: 19 Jun 2020, 14:06

Re: StrSplit not splitting?

Post by PepeLapiu » 02 Jan 2022, 20:38

boiler wrote:
02 Jan 2022, 20:23
Can you post the copied text into a code box so we can see what special characters it might contain?
It's text copied from an email (if that info can be of any use to you.
Here you go:

New contract to sell 0.00341901 BTC with PepeLapiu2

Please check your notifications page for details
I understand that it is removing the L's. But I don't get why it's not removing the R's as well. I just tought you guys told me to use "`l" and "`r" to remove lines and returns. I'll have to look back on the thread.

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

Re: StrSplit not splitting?

Post by boiler » 02 Jan 2022, 20:41

What R’s is it removing? I see R’s in the output. We didn’t say to remove `l. Line feeds and carriage returns are `n and `r — both cause new lines.

PepeLapiu
Posts: 324
Joined: 19 Jun 2020, 14:06

Re: StrSplit not splitting?

Post by PepeLapiu » 02 Jan 2022, 20:46

I think I quoted the clipboard instead of putting it in code as you requested. Here it is in code this time placed on the X between the two O's like this ----> OXO

Code: Select all

O 	
New contract to sell 0.00341901 BTC with PepeLapiu2

Please check your notifications page for details

O

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

Re: StrSplit not splitting?

Post by boiler » 02 Jan 2022, 20:52

This is the output I'm getting using your provided clipboard contents:

Code: Select all

New
contract
to
sell
0.00341901
BTC
with
PepeLapiu2



Please
check
your
notifications
page
for
details





Stop

It was generated using your code except for getting rid of the `l from the split characters and using a more efficient way to produce the output than typing out the array element names:

Code: Select all

Haystack := clipboard
MsgBox, % Haystack      
Array := StrSplit(Haystack, [A_Space,"`n","`r"]) 

for i, v in Array
	out .= v "`n"
MsgBox, % out "`nStop"

PepeLapiu
Posts: 324
Joined: 19 Jun 2020, 14:06

Re: StrSplit not splitting?

Post by PepeLapiu » 02 Jan 2022, 21:22

Well, I guess AHK finds somethng(s) in my clipboard that doesn't get seen anywhere else. Because I get different results than you do, Boiler.
Image
Image
Image
But I'm fine with it. So long as I can extract the user name and the BTC amount and hopefully, they remain always at the same location in the array.

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

Re: StrSplit not splitting?

Post by boiler » 02 Jan 2022, 22:48

As far as the warning goes, all you have to do is put out := "" at the top of your script, which seems unnecessary since it's just temporary to put the contents of the array into a MsgBox.

PepeLapiu wrote: Well, I guess AHK finds somethng(s) in my clipboard that doesn't get seen anywhere else. Because I get different results than you do, Boiler.
Why would you say that when the MsgBox you posted show the exact same output as what I posted?
output comparison.png
output comparison.png (50.15 KiB) Viewed 842 times

PepeLapiu
Posts: 324
Joined: 19 Jun 2020, 14:06

Re: StrSplit not splitting?

Post by PepeLapiu » 02 Jan 2022, 22:56

boiler wrote:
02 Jan 2022, 22:48
Why would you say that when the MsgBox you posted show the exact same output as what I posted?
Is it the exact same? Your appears to have "New" as the first element while mine produces "New" as the fourth element.

But it's fine and perfectly workable for me. As long as the elements I want (user name and BTC amount) are always at the same spot, it's perfectly workable for me.

Thank you all for your patience. I mean it.

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

Re: StrSplit not splitting?

Post by boiler » 02 Jan 2022, 23:03

I may not have copied the text from the exact same starting point because that wasn't the part that was in question. It was that your code was missing L's and smushing parts together for some reason. But anyway...
PepeLapiu wrote: But I'm fine with it. So long as I can extract the user name and the BTC amount and hopefully, they remain always at the same location in the array.
If that's the entire goal, splitting into an array and hoping things end up in the same spot is not the way to go about it. This extracts those things no matter how many line feeds and other things appear before and after that line:

Code: Select all

HayStack =
(
 	
New contract to sell 0.00341901 BTC with PepeLapiu2

Please check your notifications page for details


)
RegExMatch(Haystack, "([\d\.]+) BTC with (\w+)", m)
MsgBox, % "Qty of BTC: " m1 "`nUser name: " m2

PepeLapiu
Posts: 324
Joined: 19 Jun 2020, 14:06

Re: StrSplit not splitting?

Post by PepeLapiu » 02 Jan 2022, 23:28

boiler wrote:
02 Jan 2022, 23:03
If that's the entire goal, splitting into an array and hoping things end up in the same spot is not the way to go about it. This extracts those things no matter how many line feeds and other things appear before and after that line:

Code: Select all

HayStack =
(
 	
New contract to sell 0.00341901 BTC with PepeLapiu2

Please check your notifications page for details


)
RegExMatch(Haystack, "([\d\.]+) BTC with (\w+)", m)
MsgBox, % "Qty of BTC: " m1 "`nUser name: " m2
Why you do that? I almost killed my wife and the neighbor's dog with all the frustration around learning IniRead and StrString. Now you want me to kill who next to figure out RegExMatch? :lol:

What I was planning on doing is making sure that the element before the amount is "of" and the element after is "BTC". Than it can be safe to assume that is the right one. Not the most efficient and clean way to do it, but it'll spare the mother in law from an horrible death.

Anyways. Thanks for the code. But I'm not sure I want to include it without understanding all that stuff does. So I'll look into RegExMatch......maybe.

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

Re: StrSplit not splitting?

Post by boiler » 02 Jan 2022, 23:38

The above already makes sure it says BTC or else it won't produce a match. It can also be made to look for of as well by simply sticking that in there. Your latest example doesn't contain an "of", btw.

PepeLapiu
Posts: 324
Joined: 19 Jun 2020, 14:06

Re: StrSplit not splitting?

Post by PepeLapiu » 03 Jan 2022, 10:23

boiler wrote:
02 Jan 2022, 23:38
The above already makes sure it says BTC or else it won't produce a match. It can also be made to look for of as well by simply sticking that in there. Your latest example doesn't contain an "of", btw.
Yeah, I meant the element between 'sell' and 'BTC', not 'of' and 'BTC'.

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

Re: StrSplit not splitting?

Post by boiler » 03 Jan 2022, 10:36

This will only extract the data if the number is between "sell" and "BTC" and is followed by "with" and a name:

Code: Select all

HayStack =
(
 	
New contract to sell 0.00341901 BTC with PepeLapiu2

Please check your notifications page for details


)
RegExMatch(Haystack, "sell ([\d\.]+) BTC with (\w+)", m)
MsgBox, % "Qty of BTC: " m1 "`nUser name: " m2

Post Reply

Return to “Ask for Help (v1)”