窗口批处理/DOS脚本删除字符串中的重复单词 [英] Window batch / DOS script to remove duplicate words in a string

查看:163
本文介绍了窗口批处理/DOS脚本删除字符串中的重复单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以通过窗口批处理/DOS脚本帮助我删除字符串.

Can anyone help me with window batch / DOS script to remove in a string.

如果字符串是-

test1 test2 test1 test3 test2 test3

test1 test2 test1 test3 test2 test3

我需要一个脚本来显示为

I need a script to display as

test1 test2 test3

test1 test2 test3

推荐答案

相同的方法,您将手动执行:获取每个元素,检查是否已在输出中,否则,将其附加:

the same way, you would do it manually: take every element, check if it already is in output, if not, append it:

@echo off
setlocal enabledelayedexpansion
set "string=test1 test2 test1 test3 test2 test3"
set "newstring="
for %%i in (%string%) do (
  echo !newstring!|findstr /i "\<%%i\>" >nul || set "newstring=!newstring! %%i"
)
echo %newstring:~1%

(注意:如果要区分大小写,请删除/i)

(Note: remove /i if you want it case sensitive)

经过修改,可以处理完整的单词,而不是(可能的)子字符串.

edited to handle complete words instead of (possible) substrings.

这篇关于窗口批处理/DOS脚本删除字符串中的重复单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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