Issue with StringReplace and StringSplit in clipboard

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
RyanAyton
Posts: 49
Joined: 14 Aug 2017, 09:53

Issue with StringReplace and StringSplit in clipboard

19 Jan 2018, 08:56

Hello,

In Chrome, when I copy the information from 3 columns (for example First Name, Last Name, Age) there is only 1 return between the information when I paste it

For example, when I copy:
In Chrome, it's shown as Bob | Smith | 56
When I copy and paste this, it is shown as:

Code: Select all

Bob
Smith
56
So, I can use the following AutoHotkey to then paste this like:

First Name: Bob
Last Name: Smith
Age: 56

Code: Select all

::#css::
	StringReplace, clipboard, clipboard, `r`n, /, All
	StringSplit, data, clipboard, /,
	Send, First Name: %data1%`nLast Name: %data2%`nAge: %data3%
Return
However in Firefox, it is different.
When I copy and paste the values, it outputs as:

Code: Select all

Bob

Smith

56
So it outputs as:

First Name: Bob
Last Name:
Age: Smith

The reason why this is happening is because when I copy the values from Firefox:
data1 is "Bob"
data2 is
data3 is "Smith"

How would I get this one command to work from both Chrome and Firefox?
Would it be best to have it detect which is the active browser or
To detect if a data is empty, skip?

Thank you! :)
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Issue with StringReplace and StringSplit in clipboard

19 Jan 2018, 09:13

Probably the EOL-char needs to be replaced from `r to `n :?:
RyanAyton
Posts: 49
Joined: 14 Aug 2017, 09:53

Re: Issue with StringReplace and StringSplit in clipboard

19 Jan 2018, 09:36

Hi @BoBo
BoBo wrote:Probably the EOL-char needs to be replaced from `r to `n :?:
By this do you mean using:

Code: Select all

::#css::
	StringReplace, clipboard, clipboard, `n`n, /, All
	StringSplit, data, clipboard, /,
	Send, First Name: %data1%`nLast Name: %data2%`nAge: %data3%
Return
Because I've already tried that and it doesn't seem to work
Odlanir
Posts: 659
Joined: 20 Oct 2016, 08:20

Re: Issue with StringReplace and StringSplit in clipboard

19 Jan 2018, 12:18

This works. Copied your data from Firefox.

Code: Select all

data =
(
Bob

Smith

56
)
StringReplace, data, data, `n`n, /, All
StringSplit, data, data, /,
MsgBox %  "First Name: " data1 "`nLast Name: " data2 "`nAge: "data3
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: filipemb, mikeyww, PsysimSV, RussF and 297 guests