Windows批处理文件 - 分割字符串,字符串作为分隔符 [英] Windows Batch File - Split String With String As Delimiter

查看:670
本文介绍了Windows批处理文件 - 分割字符串,字符串作为分隔符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用一个字符串(而不是一个字符)作为分隔符在批处理文件来分割字符串。

I'm trying to split a string in a batch file using a string (rather than a character) as the delimiter.

该字符串的格式为:

string1 by string2.txt

分隔符是(是的,空间的,这个词用,其次是空间)。我想输出是:

The delimiter is by (yes, space, the word 'by', followed by space). The output I want is:

string1

string2

因此​​,基本上,由分隔符分割字符串转换成2份,并从第二字符串中删除的后缀。我怎样才能做到这一点?

So, basically, split the string into 2 parts by the delimiter by and remove the suffix from the second string. How can I do this?

推荐答案

试试这个:

for /F "tokens=1,3 delims=. " %%a in ("%string%") do (
   echo %%a
   echo %%b
)

这是,采取通过空间或点限定的第一和第三令牌...

that is, take the first and third tokens delimited by space or point...

这篇关于Windows批处理文件 - 分割字符串,字符串作为分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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