AutoHotkey Community

It is currently May 27th, 2012, 4:27 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 11 posts ] 
Author Message
PostPosted: February 25th, 2010, 11:18 pm 
Offline

Joined: February 25th, 2010, 11:10 pm
Posts: 23
Hi All,

I have a general script with a line to send search requests to Google. The code is:

Code:
; Google Search Box
^Delete::
InputBox, varInput, Google Search,
,, 540, 180,,,, 90,
if ErrorLevel = 0 ; OK or Enter
{
   if varInput <> ; if input not empty
            Run, http://www.google.ca/search?q=%varInput% ; execute the command
      }
Return


When I send a search request including quotation marks with more than one word, the scripts breaks--nothing happens, and there is no error code.

So, sending (without brackets) <test test test> works fine. Sending <test test "test"> works fine. But sending <test "test test"> does nothing at all. Can anyone explain how I can fix this?

Thanks!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2010, 11:21 pm 
Offline

Joined: December 24th, 2008, 3:25 am
Posts: 1401
Location: :noitacoL
Spaces are treated different in urls. They invlove %'s and stuff.

I don't know exactly off the top of my head, but its lke %a20% or something, you have probably seen them 1000 times and never even noticed. Google it :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2010, 11:21 pm 
Offline

Joined: December 24th, 2008, 3:25 am
Posts: 1401
Location: :noitacoL
Carcophan wrote:
Google it :)


http://www.webmasterworld.com/forum92/2045.htm


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 26th, 2010, 12:20 am 
Offline

Joined: April 19th, 2005, 10:26 am
Posts: 2249
Location: switzerland
an example
Code:
LAC=Grace Chang
transform,S,chr,32    ;space
transform,P,chr,37    ;procent
stringreplace,LAC,LAC,%S%,+,all
LAC=%P%22%LAC%%P%22
URL1=http://www.google.com/search?complete=1&hl=en&num=100&q=%LAC%
run,%URL1%
return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 26th, 2010, 12:33 am 
Offline

Joined: February 25th, 2010, 11:10 pm
Posts: 23
Thanks, that explains the problem.

I'm not a programmer, so I don't know how to write the code that replaces spaces between quotation marks in my query with %20. Can someone please show me how that's done?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 26th, 2010, 1:04 am 
Offline

Joined: April 19th, 2005, 10:26 am
Posts: 2249
Location: switzerland
works for me also when I added + instead space
Code:
transform,S,chr,32    ;space
transform,P,chr,37    ;procent

InputBox, varInput, Google Search,,, 540, 180,,,, 90,
;stringreplace,varInput,varInput,%S%,+,all   ;replace space with +
stringreplace,varInput,varInput,%S%,`%20,all  ;replace space with `%20
varInput=%P%22%varInput%%P%22   ;add "  "   or  `%22
URL1=http://www.google.com/search?complete=1&hl=en&num=100&q=%varInput%

if ErrorLevel = 0 ; OK or Enter
     {
     if varInput <> ; if input not empty
            {
            Run,%URL1%
            }
     }
Return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 26th, 2010, 2:26 am 
Offline

Joined: February 25th, 2010, 11:10 pm
Posts: 23
garry wrote:
works for me also when I added + instead space
Code:
(See code above)


Thanks for this. I've tried it and it does replace the spaces with the %20, but it has a bug.

If I search for (minus brackets) < test "search one" >, it searches Google for < "test search one" >. Can you fix this by any chance?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 26th, 2010, 6:49 am 
Offline

Joined: April 19th, 2005, 10:26 am
Posts: 2249
Location: switzerland
yes , this replace your input " with `%22
Code:
transform,S,chr,32    ;space
InputBox, LAC1, Google Search,,, 540, 180,,,, 90,
stringreplace,LAC1,LAC1,%S%,`%20,all    ;-- replace space
stringreplace,LAC1,LAC1,`",`%22,all     ;-- replace bracket
URL1=http://www.google.com/search?complete=1&hl=en&num=100&q=%LAC1%
if LAC1<>
 Run,%URL1%
Return


EDIT corrected


Last edited by garry on February 26th, 2010, 5:55 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 26th, 2010, 4:03 pm 
Offline

Joined: February 25th, 2010, 11:10 pm
Posts: 23
That has solved the quotation marks issue, but now there is this problem:

Searching for < test "test test" > works correctly, but searching for < test > does nothing at all. It seems the query is only recognized when there are quotation marks.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 26th, 2010, 5:58 pm 
Offline

Joined: April 19th, 2005, 10:26 am
Posts: 2249
Location: switzerland
(corrected above)
sorry, not tested all , hope it works now
tested
"Grace Chang" "Ge Lan"
-and-
Dumaguete


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 26th, 2010, 7:03 pm 
Offline

Joined: February 25th, 2010, 11:10 pm
Posts: 23
It works perfectly now. Thanks very much...no apology necessary. You've been a great help!


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Mickers, rbrtryn, Yahoo [Bot] and 66 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group