[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文本处理] 批处理for语句如何遍历多列的内容

本帖最后由 pcl_test 于 2016-11-10 19:11 编辑

在写一个批处理下载56的视频, 通过网页返回一个XML, 里头包含了一个长字符串

具体文本: http://vxml.56.com/json/MzIwMDg2NjE/?src=out
  1. {"info":{"vid":"32008661","bimg":"http://v155.56img.com/images/6/26/zhssti56olo56i56.com_zhajm_120713452170_b.jpg","textid":"MzIwMDg2NjE","m_download":"y","img":"http://v155.56img.com/images/6/26/zhssti56olo56i56.com_zhajm_120713452170.jpg","key":"bbc43c623c3ddd7fc1a78a545a6e88e1","record":"","tag":"六方位,凯美瑞,凯美瑞六方,,","rela_opera":-4,"sohu_cdn":"0","opera_id":-4,"Subject":"凯美瑞六方位绕车","hd":0,"duration":"1132266","rfiles":[{"filesize":31143899,"totaltime":1132334,"url":"http://f1.r.56.com/f1.c36.56.com/flvdownload/6/26/zhsst@56.com_56flv_zhajm_120713452170.flv?v=1&t=YkNGvtFJpQg9QSl_XmSadw&r=63359&e=1478862265&tt=1132&sz=31143899&vid=32008661","type":"normal","keyframe":""}],"tags":"六方位,凯美瑞,凯美瑞六方,,","user_id":"zhsst","cid":"11","movie":{"m_copyright":"","version":"","keyword":"","class1":"e","last_sub_index":0,"chk_yn":"d","finished":"","coop_vid":"","copyright":"n","total_items":0,"coop":""},"reserveIp":""},"msg":"ok","p2p":1,"segsize":30,"st":1478775865948,"status":"1"}
复制代码
通过
  1. for /f  tokens^=1^-31*^ delims^={^,:}^" %%a in (tmp.txt) do (echo %%a %%b %%c %%d)
复制代码
可以分别显示双引号里头的内容 (除了http://.... 被分割两段)

问题是最多只有32组数据, 如果更多数据的话 怎么遍历呢?

另外 使用
  1. @echo off&setlocal EnableDelayedExpansion
  2. set Text="ABCDEFGHIJKLMNOPQRSTUV[\]^_`abcdefghijklmnopqrstuvwyz{|}~
  3. set index=1
  4. for /f  tokens^=1^-31*^ delims^={^,:}^" %%A in (tmp.txt) do (
  5.   for /l %%1 in (1 1 31) do (
  6.     set pChar=%Text:~!index!,1%
  7.     echo %%!pChar!
  8.     set /a index+=1
  9.   )
  10. )
复制代码
并不能遍历所有的变量....

怎么才能针对一个长字符, 遍历里头所有的列呢? 求教各位高手....

批处理超越for命令tokens极限分割字符串
http://bbs.bathome.net/thread-5548-1-1.html
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

回复 2# Batcher


   万分感谢! 找了好久都没找到...研究了好久...

TOP

返回列表