简体   繁体   English

Windows批处理文件读取文本文件并将全部转换为大写

[英]Windows batch file read text file and convert all to uppercase

I just simply want to replace all the text in the text file convert to uppercase. 我只想简单地将文本文件中的所有文本替换为大写。

For example of abc.txt 例如abc.txt

[Before conversion] First Name, Last Name, Full Name Brad, Pitt, Brad Pitt [转换前]名字,姓氏,全名布拉德,皮特,布拉德皮特

[After conversion] FIRST NAME, LAST NAME, FULL NAME BRAD, PITT, BRAD PITT [转换后]第一个名字,最后一个名字,全名BRAD,PITT,BRAD PITT

Is that possible?? 那可能吗??

The Batch file below do what you want, but if the file to convert is large this method is slow... 下面的批处理文件做你想要的,但如果要转换的文件很大,这个方法很慢......

@echo off
setlocal EnableDelayedExpansion
for /F "delims=" %%a in (%1) do (
   set "line=%%a"
   for %%b in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
      set "line=!line:%%b=%%b!"
   )
   echo !line!
)

To use this program, place the name of the file in the first parameter. 要使用此程序,请将文件名放在第一个参数中。 For example, if this Batch file is called TOUPPER.BAT: 例如,如果此批处理文件名为TOUPPER.BAT:

toupper abc.txt

Note that this program eliminate empty lines and any exclamation mark existent in the file. 请注意,此程序消除了空行和文件中存在的任何感叹号。 These limitations may be fixed if needed, but the program becomes even slower... 如果需要,可以修复这些限制,但程序变得更慢......

Antonio 安东尼奥

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM