Windows 批处理脚本中的 URL 编码 [英] URL Encode in Windows Batch Script

查看:42
本文介绍了Windows 批处理脚本中的 URL 编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Windows 批处理脚本,用于进行快速的 Google 搜索.但是,我无法弄清楚如何对特殊字符进行一般编码.就像我尝试搜索 C# 一样,井号会破坏它.这是我的代码:

I have a Windows batch script that I use to do quick Google searches. However, I can't figure out how to generically encode special characters. Like if I try to search for C#, the pound sign breaks it. Here is my code:

SET q="https://www.google.com/#q=%*"
SET q=%q: =+%
chrm %q%

推荐答案

无需安装任何外部工具:

Without installing any external tools:

@echo off
setlocal


set "string=gibberish+?blahblah@"


:: Define simple macros to support JavaScript within batch
set "beginJS=mshta "javascript:code(close(new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).Write("
set "endJS=)));""



:: FOR /F does not need pipe
for /f %%N in (
  '%beginJS% encodeURIComponent("%string%") %endJS%'
) do set encoded=%%N
echo %string% -^> %encoded%

这篇关于Windows 批处理脚本中的 URL 编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆