用字符串作为分隔符分割字符串 [英] Split string with string as delimiter

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

问题描述

我正在尝试使用字符串(而不是字符)作为定界符在批处理文件中分割字符串.

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

分隔符为by(是,空格,单词"by",后跟空格).我想要的输出是:

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

string1

string2

因此,基本上,用定界符by将字符串分成两部分,并从第二个字符串中删除后缀.我该怎么办?

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...

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

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