Search and Replace Within a Variable

Post your questions and help other users.

Moderator: Martin

Post Reply
User avatar
ltplenus
Posts: 23
Joined: 10 Jan 2015 21:39

Search and Replace Within a Variable

Post by ltplenus » 08 Feb 2015 21:18

Hi Martin,

I have a flow that sends the url of a voice search to my computer . To accomplish that im using the Autoremote plugin and EventGhost on my computer to receive the message and open the url.
The problem is that EventGhost doesn't like blank spaces at all so a search for '' auto magic'' turns into a search for ''auto'' only...
The search is been passed by a variable called ''avcommnofilter'' ( the variable is provided by the AutoRemote plugin ) and my question is: how to replace the spaces within the variable with a + ??? ( like: auto+magic)
Thank you !

User avatar
TheBrain1984
Posts: 137
Joined: 07 Aug 2013 08:17
Location: Germany

Re: Search and Replace Within a Variable

Post by TheBrain1984 » 09 Feb 2015 22:00

Action: Script

var_b = replace(var_a, "auto magic", "auto+magic")

OR

var_b = replaceAll(var_a, "auto magic", "auto+magic")

var_a is the variable that includes the string "auto magic" and var_b is the variable that get's the string with "auto+magic"

User avatar
ltplenus
Posts: 23
Joined: 10 Jan 2015 21:39

Re: Search and Replace Within a Variable

Post by ltplenus » 09 Feb 2015 23:16

How would i go about it TheBrain ??

Something like this ?

var_b = replaceAll(var_avcommnofilter, " ", "+")

User avatar
TheBrain1984
Posts: 137
Joined: 07 Aug 2013 08:17
Location: Germany

Re: Search and Replace Within a Variable

Post by TheBrain1984 » 10 Feb 2015 11:51

This will replace all Spaces to "+". If this is what you want, than oyur solution would be correct.

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Search and Replace Within a Variable

Post by Martin » 10 Feb 2015 20:01

It sounds like the text might be passed to the computer as part of an URL parameter. If this is the case, you would also have to escape some other characters like question marks and equal signs.
To do this you can use function var_b = encodeURLForm(var_a);.

User avatar
ltplenus
Posts: 23
Joined: 10 Jan 2015 21:39

Re: Search and Replace Within a Variable

Post by ltplenus » 10 Feb 2015 20:53

I've tried a few things without success. Could you guys explain in details or make the necessary changes for me ?
http://automagic4android.com/flow.php?i ... b953ac5a7a
Thanks !

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Search and Replace Within a Variable

Post by Martin » 11 Feb 2015 20:23

Sorry, I don't use the plugins used by your flow so I'm not really able to test the flow.

I assume that you could change the following line in the AutoRemote action plugin:
putString("message", "http://google.com/search?q={avcommnofilter}");
to
putString("message", "http://google.com/search?q={encodeURLFo ... mnofilter)}");

User avatar
ltplenus
Posts: 23
Joined: 10 Jan 2015 21:39

Re: Search and Replace Within a Variable

Post by ltplenus » 11 Feb 2015 20:45

WONDERFUL !

Thats a solution for all my problems related to Phone/PC communication !
Martin, where is the ''DONATE BUTTON'' my friend ?
I need to click it a few times :mrgreen:

Post Reply