将“集合”转换为小写

将“集合”转换为小写

我正在处理一个要求输入昵称(但要大写)的 .bat 文件

set /p nickname="Please enter your uppercase name!:

我想知道我是否可以让蝙蝠存储原始(大写)昵称和全部小写昵称。

所以我可以这样做

%nickname%\files\avatar\1.png

或者

%nickname_lowercase%\files\avatar\1.png

我不想要求用户输入小写的昵称,我只想将用户输入的内容转换为小写并将其存储在“集合”或类似的东西中。这有点复杂,如果我无法解释,请原谅。

答案1

如何将变量的内容转换为小写?

使用以下批处理文件:

SETLOCAL ENABLEDELAYEDEXPANSION
set /p nickname="Please enter your uppercase name!:
rem save the name, use "s in case there are space in the name
set "_UpperNick=nickname"
call LoCase nickname
set "_LowerNick=nickname"
echo _UpperNick
echo _LowerNick
ENDLOCAL
GOTO:EOF

:LoCase
:: Subroutine to convert a variable VALUE to all lower case.
:: The argument for this subroutine is the variable NAME.
SET %~1=!%~1:A=a!
SET %~1=!%~1:B=b!
SET %~1=!%~1:C=c!
SET %~1=!%~1:D=d!
SET %~1=!%~1:E=e!
SET %~1=!%~1:F=f!
SET %~1=!%~1:G=g!
SET %~1=!%~1:H=h!
SET %~1=!%~1:I=i!
SET %~1=!%~1:J=j!
SET %~1=!%~1:K=k!
SET %~1=!%~1:L=l!
SET %~1=!%~1:M=m!
SET %~1=!%~1:N=n!
SET %~1=!%~1:O=o!
SET %~1=!%~1:P=p!
SET %~1=!%~1:Q=q!
SET %~1=!%~1:R=r!
SET %~1=!%~1:S=s!
SET %~1=!%~1:T=t!
SET %~1=!%~1:U=u!
SET %~1=!%~1:V=v!
SET %~1=!%~1:W=w!
SET %~1=!%~1:X=x!
SET %~1=!%~1:Y=y!
SET %~1=!%~1:Z=z!
GOTO:EOF

来源批处理文件 - 如何...将字符串转换为大写或小写

答案2

对于预测字符集,此子字符串Set !var:A=a!有效,并且只适用于预定义子字符串/

对于这种类型的任务,为什么不寻求一些帮助这使得使用非常规口音和辅音成为可能è, È, ä, Ä, ñ, Ñ, ç, Ç 等。

其中/将产生代码,它将在运行时被编译并执行....

解决了可能的用户输入问题,其中序列带有重音,并且元音/辅音与常规的元音/辅音不同[阿兹]和/或[亞洲]

注意:- 还可与带空格的昵称和/或撰写名字


@echo off && setlocal EnableDelayedExpansion 

cd /d "%~dp0" && title <nul && title ...\%~dpnx0 /// !time:~0,8! !date!
set "_where=%__appdir__%where.exe" && set "_csc=%windir%\Microsoft.NET"
set "_findstr=%__APPDIR__%\findstr.exe" && del /q /f "%tmp%\ToUpLower.*" 2>nul >nul 

>"%temp%\ToUpLower.cs"^
   ( 
echo= using System; namespace SUQ1522019 ^{class Program ^{static void Main(string[] args^) ^{
echo= if (args.Length==2 ^&^& args[0].ToLower(^)=="-l"^) ^{Console.WriteLine(args[1].ToLower(^)^);^} 
echo= if (args.Length==2 ^&^& args[0].ToLower(^)=="-u"^) ^{Console.WriteLine(args[1].ToUpper(^)^);^}^}^}^}
   ) && set "_arg=/t:exe /out:"%temp%\ToUpLower.exe" "%temp%\ToUpLower.cs" /platform:anycpu "

:loop
if exist "%temp%\ToUpLower.exe" goto :next
for /l %%L in (4 -1 2)do for /f "tokens=*" %%i in ('!_where! /r "!_csc!" csc.exe ^|!_findstr! /lic:"\v%%~L\."')do (
   set "_compiller="%%~i" !_arg! /unsafe+ /w:0 /o /nologo" && call !_compiller! && set /p "_nick="Please enter nickname: "
   if not "!_nick!"=="" (goto :next) else cls && goto :loop
  )

:next
for /f tokens^=^*delims^=^"  %%# in ('echo[!_nick!') do for /f tokens^=^*delims^=^" %%U in ('
call "%temp%\ToUpLower.exe" -u "%%#"')do set "_up_case_nick=%%~U" && for /f tokens^=^*delims^=^" %%l in ('
call "%temp%\ToUpLower.exe" -l "%%#"')do set "_low_case_nick=%%~l" ) else goto :loop

echo/ Your input nickname is: !_nick!
echo/   Your input upcase is: !_up_case_nick!
echo/  Your input lowcase is: !_low_case_nick!

echo/ >nul 2>nul copy "%tmp%\ToUpLower.exe" "." 
del /q /f "%tmp%\ToUpLower.*" >nul 2>nul && endlocal & goto :EOF

  • 输入的输出 ==To Up Lower
 Please enter nickname: To Up Lower

Your input nickname is: To Up Lower
  Your input upcase is: TO UP LOWER
 Your input lowcase is: to up lower

ToUpLower.cs 没有转义的代码:


 using System; namespace SUQ1522019 {class Program {static void Main(string[] args) {
 if (args.Length==2 && args[0].ToLower()=="-l") {Console.WriteLine(args[1].ToLower());} 
 if (args.Length==2 && args[0].ToLower()=="-u") {Console.WriteLine(args[1].ToUpper());}}}}

ToUpLower.cs 没有转义和缩进的代码:


using System
namespace SUQ1522019 
{
   class Program 
   {
      static void Main(string[] args)
      {
         if (args.Length==2 && args[0].ToLower()=="-l") 
         {
            Console.WriteLine(args[1].ToLower());
         } 

         if (args.Length==2 && args[0].ToLower()=="-u") 
         {
            Console.WriteLine(args[1].ToUpper());
         }
      }
   }
}

  • 代码是编译/测试csc.exe版本:
c:\Windows\Microsoft.NET\Framework\v2.0.50727\csc.exe
c:\Windows\Microsoft.NET\Framework\v3.5\csc.exe
c:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe
c:\Windows\Microsoft.NET\Framework64\v2.0.50727\csc.exe
c:\Windows\Microsoft.NET\Framework64\v3.5\csc.exe
c:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe

  • 这是命令行习惯编译代码:
c:\Windows\Microsoft.NET\Framework\v2.0.50727\csc.exe /t:exe /out:"%tmp%\ToUpLower.exe" "%tmp%\ToUpLower.cs" /platform:anycpu /unsafe+ /w:0 /o /nologo 

  • ToUpLower.exe用法 上部至 -> 下部
ToUpLower.exe -l STRING 

:: if have space, use quote:

ToUpLower.exe -l "THIS STRING" 

:: or ..

ToUpLower.exe -L STRING

:: if have space, use quote:

ToUpLower.exe -L "THIS STRING"


  • ToUpLower.exe用法 下至 -> 上

ToUpLower.exe -u string

:: if have space, use quote:

ToUpLower.exe -u "this string"

:: or ..

ToUpLower.exe -U string

:: if have space, use quote:

ToUpLower.exe -U "this string"


保持ToUpLower.exe, 消除echo/copy 命令


回声/>nul 2>nul 复制“%tmp%\ToUpLower.exe” “。”
  • 此命令行将复制ToUpLower.exe%temp%与你的 bat 运行所在的文件夹相同。

编程指南 C#:


  • 编辑:此代码将按以下顺序使用找到的第一个 .Net Framework 编译 C# 源代码:
c:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe
c:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe
c:\Windows\Microsoft.NET\Framework\v3.5\csc.exe
c:\Windows\Microsoft.NET\Framework64\v3.5\csc.exe
c:\Windows\Microsoft.NET\Framework\v2.0.50727\csc.exe
c:\Windows\Microsoft.NET\Framework64\v2.0.50727\csc.exe

  • 第二种选择是添加/加入ToUpLower.exe可执行文件batch文件,使用base64字符串和运行时解码

    你可以使用%__APPDIR__%Certutil.exe,适用于 Windows。

注意:- 还可与带空格的昵称和/或撰写名字


@echo off && setlocal EnableDelayedExpansion 

cd /d "%~dp0" && title <nul
title ...\%~dpnx0 /// !time:~0,8! !date!
del /q /f "%temp%\ToUpLower.exe" 2>nul >nul

%__APPDIR__%certutil.exe -f -decode "%~dpnx0" "%tmp%\ToUpLower.exe" 2>nul >nul

:loop
cls & echo/ & set /p "_nick="Please enter nickname: "

if not "!_nick!"==""  (
for /f tokens^=^*delims^=^"  %%# in ('echo[!_nick!') do for /f tokens^=^*delims^=^" %%U in ('
call "%temp%\ToUpLower.exe" -u "%%#"')do set "_up_case_nick=%%~U" && for /f tokens^=^*delims^=^" %%l in ('
call "%temp%\ToUpLower.exe" -l "%%#"')do set "_low_case_nick=%%~l" ) else goto :loop

echo/ Your input nickname is: !_nick!
echo/   Your input upcase is: !_up_case_nick!
echo/  Your input lowcase is: !_low_case_nick!

echo/ 2>nul >nul copy /y "%tmp%\ToUpLower.exe" "." 
del /q /f "%tmp%\ToUpLower.*" >nul 2>nul && endlocal & goto :EOF

rem :: Strings Base64 to decode in run time to generate/use the file: "%tmp%\ToUpLower.exe"

-----BEGIN CERTIFICATE----- TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAAAAAA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAA= -----END CERTIFICATE-----

  • 命令行用于解码Base64归档"%tmp%\ToUpLower.exe"
%__APPDIR__%certutil.exe -f -decode "%~dpnx0" "%tmp%\ToUpLower.exe"  2>nul >nul

抱歉我的水平有限英语

答案3

将文本转换为大写:(字符限制 255)

for /f "tokens=2 delims=-" %i in ('find "" "lower case text" 2^>^&1') do set i=%i& echo !i:~1!

转换为小写:(字符限制 255)

type nul > "UPPER CASE"
dir /l /b "UPPER CASE"

或者

md al & cd al
echo:> "SOME LONG FILENAME in here"
dir /l /b

更改整个文件的大小写:

set case=upper
set file=line.txt

if exist out.txt del out.txt

for %i in (%file%) do set n=%~zi
fsutil file createnew A %n% >nul
fc /b A %file% | more +1 > B

type nul > A
for /f "tokens=3" %i in (B) do (

if %case%==lower (
if 0x%i gtr 0x40 (if 0x%i lss 0x5b (set /a a=0x%i+0x20 >nul) else set /a a=0x%i >nul) else set /a a=0x%i >nul
)
if %case%==upper (
if 0x%i gtr 0x60 (if 0x%i lss 0x7b (set /a a=0x%i-0x20 >nul) else set /a a=0x%i >nul) else set /a a=0x%i >nul
)
cmd /c exit /b !a! & set hex=!=exitcode:~-2!& set /p=!hex! <nul

) >> A

certutil -decodehex A out.txt

del A & del B

笔记:

exitcodeASCII&forfiles可以完成相同的任务,而且可能更快,使用更多代码来处理 TAB、SPACE、CR 和 LF。

在 Win 10 cmd 上测试

示例输出:(摘自 out.txt)

原来的

起初,时间存在。随着时间从出现点向外扩散,不断增大的空间中虚空的压力拉伸了零空间中维持时间的能量,随着真空温度的降低,能量聚集在一起的可能性也随之增加,从而导致在温度较低的区域产生物质。

一些物质变得太大,以至于开始吸引周围的其他物质,从而使其自身的温度再次升高,并最终通过突然的超新星或慢脉冲星和类星体辐射冷却下来。这种加热和冷却最终稳定在共振状态,在宇宙的中心跳动着生命。

大写

起初,时间存在。随着时间从出现点向外扩散,不断增大的空间中的虚空压力拉伸了零空间中保持时间的能量,随着真空温度的降低,能量聚集在一起的可能性也随之增加,导致在温度较低的区域产生物质。

一些物质 & > < 变得过于巨大,以至于它开始吸引周围的其他物质,从而再次升高其自身的温度,并最终通过突然的超新星或慢脉冲星和类星体辐射冷却下来。这种加热和冷却最终稳定在共振中,在宇宙的中心跳动着生命。

小写

起初,有时间。随着时间从出现点扩散,不断增加的空间中的虚空压力拉伸了保持零空间时间的能量,随着真空温度的降低,能量聚集在一起的可能性增加了,从而在比其他区域更冷的区域产生物质。

一些物质 & > < 变得太大,以至于它开始吸引周围的其他物质,从而使其自身的温度再次升高,并最终通过突然的超新星或慢脉冲星和类星体辐射冷却下来。这种加热和冷却最终稳定在一种共振状态,在宇宙的中心跳动着生命。

版权所有©,保留所有权利
所提供的代码仅供 stackexchange 使用,不得在本网站之外发布。

相关内容