SV650.org - SV650 & Gladius 650 Forum

SV650.org - SV650 & Gladius 650 Forum (http://forums.sv650.org/index.php)
-   Idle Banter (http://forums.sv650.org/forumdisplay.php?f=116)
-   -   windows script help needed (http://forums.sv650.org/showthread.php?t=93266)

timwilky 13-07-07 02:51 PM

windows script help needed
 
I need to encode some text in order to use it within a url.

for instance space characters need to be encoded as %20 etc.

I was tying to use the character substitution in an environment variable

for instance

SET STRING=%1%
SET STRING=%STRING: =%20% (How to I escape the % in the %20)
echo %STRING%

Where the argument to the script would be the text to encode " delimited, ie. "encode this string" where I would expect the output to be "encode%20this%20string"

Otherwise I am going to have to write a bit of C just to do this noddy requirement.

plowsie 13-07-07 02:54 PM

Re: windows script help needed
 
Encode was where i got confused Tim sorry mate lol

johnnyrod 13-07-07 03:22 PM

Re: windows script help needed
 
Does this help? Can you adapt it? Try PMing TSM, he's a geek.

http://www.syronex.com/antispam/help...cipient-mailto

timwilky 13-07-07 03:25 PM

Re: windows script help needed
 
unfortunately that is javascript. What I am attempting to do is format arguments that I will pass to a wget command. So they have to look as if a browser etc has already encoded them

rigor 13-07-07 03:29 PM

Re: windows script help needed
 
I'm guessing it's not just spaces your trying to encode as %20

If it is, does this little batch file help?

@echo off
echo %1%%20%2%%20%3

run it as test.bat test1 test2 test3
and the output is
test1%20test2%20test3

Probably a bit basic, and not sure how you would make it work for different length strings though ....

TSM 13-07-07 05:05 PM

Re: windows script help needed
 
i assume that you are using the linux "wget" port, you could with a perl script do below.

Code:

#!/usr/bin/perl

sub URLenc{
$urlstr = $_[0];
$urlstr =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg;
return $urlstr;
}

print URLenc(shift);

just realised that if you are using wget then if you put the url in """" etc then it automaticly does the convert for you,
Code:

wget "http://server/file to get.html"


All times are GMT. The time now is 12:27 PM.

Powered by vBulletin® - Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.