标题: 如何查找“/"后面的字符输出为变量?
[打印本页]
作者: dj0733
时间: 2008-7-5 15:36
标题: 如何查找“/"后面的字符输出为变量?
打比方,
set /p url=
http://wwww.szdddd.com/7893.html
我如何在url 这段字符里找到7893输出为另一个变量?
因为我要递增7893.html 7894.html ............
谢谢
作者: HAT
时间: 2008-7-5 15:54
@echo off
set url=http://wwww.szdddd.com/7893.html
set urltmp=%url:/=.%
for /f "tokens=5 delims=." %%a in ("%urltmp%") do echo %%a
作者: dj0733
时间: 2008-7-5 16:30
貌似不行。数字一长就不行。http://wx.kanunu.cn/files/article/html/5/53721/3764203.html
作者: hmily88
时间: 2008-7-5 19:42
@Echo off
set url=http://wx.kanunu.cn/files/article/html/5/53721/3764203.html
:loop
if not "%url%"=="%url:/=%" (call :xyz) else (goto end)
goto loop
:xyz
for /f "tokens=1* delims=/" %%a in ("%url%") do (set "url=%%b")
goto :eof
:end
set "url=%url:.html=%"
set "url=%url:.htm=%"
echo %url%
pause
exit
考虑到网页文件的扩展名有时会是.htm,所以加了句set "url=%url:.htm=%"
[
Last edited by hmily88 on 2008-7-5 at 07:47 PM ]
作者: qianmo717
时间: 2008-7-5 20:02
@echo off
setlocal EnableDelayedexpansion
set str1=http://wwww.szdddd.com/7893.html
for %%i in (%str1%) do (
echo %%~nxi
set str3=%%~xi
set str2=%%~ni
for /l %%a in (1,1,10) do (
set /a str2+=1
echo !str2!!str3!
)
)
pause>nul
作者: balinger
时间: 2008-7-5 20:24
@echo off
set url=http://wx.kanunu.cn/files/article/html/5/53721/3764203.html
for /f "delims=" %%i in ("%url%") do (
echo %%~ni
echo %%~xi
echo %%~nxi
)
pause
作者: metoo
时间: 2008-7-5 20:30
@echo off&setlocal enabledelayedexpansion
set url=http://wx.kanunu.cn/files/article/html/5/53721/37642034.html
set url2=%url:/=\%
for %%a in ("%url2%") do (
set url2=%%~na
echo !url2!
)
偷了把鸡。。应该没啥问题
[
Last edited by metoo on 2008-7-5 at 08:31 PM ]
作者: metoo
时间: 2008-7-5 20:32
- - !发现楼上不转斜杠也行。。失败。。匿了
作者: ywwywwjm
时间: 2008-7-6 01:56
echo
http://wx.kanunu.cn/files/article/html/5/53721/37642034.html|gawk -F[/.] "{print $(NF-1)}"
作者: bat-zw
时间: 2008-7-6 11:38
标题: 我也来一个,请楼主自己测试吧
@echo off
set /p url=url?
for /f "tokens=2 delims=html" %%i in ("%url%") do set str=%%i&call :lp
pause>nul&goto :eof
:lp
set a=%str:~-1%
set var=%a%%var%
if "%a%" neq "/" set str=%str:~,-1%&goto lp
cls&echo %var:~1,-1%.html
作者: moniuming
时间: 2008-7-6 12:08
试试这个?
@echo off
set "var=http://wx.kanunu.cn/files/article/html/5/53721/3764203.html"
:again
for /f "tokens=1* delims=/." %%a in ("%var%") do (
if not "%%b"=="html" (
set var=%%b&goto :again
) else (
echo %%a
)
)
pause
作者: HAT
时间: 2008-7-6 19:52
凑趣
echo http://wx.kanunu.cn/files/article/html/5/53721/3764203.html | sed "s/.*\///" | gawk -F "." "{print $1}"
sed.exe
http://upload.cn-dos.net/img/561.zip
gawk.exe
http://upload.cn-dos.net/img/548.zip
作者: 20080610
时间: 2008-7-7 12:03
for %a in (http://wx.kanunu.cn/files/article/html/5/53721/37642034.html) do @echo %~na