分成三个空格-批处理脚本 [英] Split by three spaces - batchscript
本文介绍了分成三个空格-批处理脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个这样的字符串.
I have a string like this.
adsads d b c dsad ds ads
如何分割此字符串(在3个空格上)以从该字符串中获得d b c?
How do I split this string (on 3 spaces) to obtain d b c from this string?
推荐答案
@ECHO OFF
SETLOCAL
SET "string=adsads d b c dsad ds ads"
FOR /f "tokens=1delims=#" %%p IN ("%string: =#%") DO ECHO token 1 is "%%p"
FOR /f "tokens=2delims=#" %%p IN ("%string: =#%") DO ECHO token 2 is "%%p"
FOR /f "tokens=3delims=#" %%p IN ("%string: =#%") DO ECHO token 3 is "%%p"
FOR /f "tokens=1,3delims=#" %%p IN ("%string: =#%") DO ECHO token 1 is "%%p"; token 3 is "%%q"
GOTO :EOF
在这里,for /f
解析提供的字符串(用引号引起来),并将指定的令牌编号分配给%%p
(如果%%q
,%%r
指定了多个 token ...)
Here, for /f
parses the string supplied (in quotes) and assigns the nominated token number to %%p
(and if more than 1 token is specified to %%q
, %%r
...)
引号之间的字符串是通过用#
替换 Space Space Space 构造的-#是一个否则不会出现的字符出现在字符串中.
The string between the quotes is constructed by substituting #
for SpaceSpaceSpace - # being a character that doesn't otherwise occur in the string.
这篇关于分成三个空格-批处理脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文