Log in

View Full Version : windows script help needed


timwilky
13-07-07, 02:51 PM
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
Encode was where i got confused Tim sorry mate lol

johnnyrod
13-07-07, 03:22 PM
Does this help? Can you adapt it? Try PMing TSM, he's a geek.

http://www.syronex.com/antispam/help/protect-form-recipient-mailto

timwilky
13-07-07, 03:25 PM
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
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
i assume that you are using the linux "wget" port, you could with a perl script do below.

#!/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,
wget "http://server/file to get.html"