web-dev-qa-db-ja.com

「セット」を小文字に変換する

ニックネーム(ただし大文字)を要求する.batファイルに取り組んでいます

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

そして、私はコウモリに元の(大文字の)ニックネームとすべて小文字のニックネームの両方を保存できるかどうか疑問に思います。

だから私はそれをすることができます

%nickname%\files\avatar\1.png

または

%nickname_lowercase%\files\avatar\1.png

ユーザーに小文字のニックネームを要求するのではなく、ユーザーが入力したものを小文字に変換して「セット」などに保存するだけです。少し複雑ですが、説明できなくて申し訳ありません。

4
Selim Karaman

変数の内容を小文字に変換するにはどうすればよいですか?

次のバッチファイルを使用します。

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

ソース バッチファイル-操作方法...文字列を大文字または小文字に変換

1
DavidPostill

予測文字セットの場合、このサブストリングSet !var:A=a!は機能し、bat / cmd事前定義サブストリングでのみ機能します。

このタイプのタスクについては、c#を少し助けてみてください。これにより、型破りなアクセントや子音を扱うことができますè、È、ä、Ä、ñ、Ñ、ç 、Çなど

bat / cmdc#コードを生成する場合、実行時にコンパイルおよび実行されます....

これは、シーケンスにアクセントが付いており、母音/子音が従来のものとは異なる、可能なユーザー入力を解決します[a-z]および/または[A_Z]

Obs:-スペースを含むニックネームまたは構成名でも使用できます


@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.csc#コード:


 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.csc#エスケープおよびインデントなしのコード:


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());
         }
      }
   }
}

  • このc#コードは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#コードで使用されます:
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コマンドから削除します。


echo/ > nul 2> nul copy "%tmp%\ ToUpLower.exe" "。" 
  • このコマンドラインは、ToUpLower.exe%temp%から、バットが実行されているのと同じフォルダにコピーします。

プログラミングガイド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

  • 2番目のオプションは、base64文字列と実行時のデコードを使用して、batchファイルで追加/結合ToUpLower.exe実行可能ファイルにすることです。

    Windowsで利用可能な%__APPDIR__%Certutil.exeを使用してできること.

Obs:-スペースを含むニックネームまたは構成名でも使用できます


@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//8AALgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAgAAAAA4fug4AtAnNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5vdCBiZSBydW4gaW4gRE9TIG1vZGUu
DQ0KJAAAAAAAAABQRQAATAEDAPztNl4AAAAAAAAAAOAAAgELAQgAAAYAAAAGAAAAAAAAHiUAAAAgAAAAQAAAAABAAAAg
AAAAAgAABAAAAAAAAAAEAAAAAAAAAACAAAAAAgAAAAAAAAMAQIUAABAAABAAAAAAEAAAEAAAAAAAABAAAAAAAAAAAAAA
ANAkAABLAAAAAEAAAKgCAAAAAAAAAAAAAAAAAAAAAAAAAGAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAACAAAAAAAAAAAAAAACCAAAEgAAAAAAAAAAAAAAC50ZXh0AAAAJAUAAAAgAAAA
BgAAAAIAAAAAAAAAAAAAAAAAACAAAGAucnNyYwAAAKgCAAAAQAAAAAQAAAAIAAAAAAAAAAAAAAAAAABAAABALnJlbG9j
AAAMAAAAAGAAAAACAAAADAAAAAAAAAAAAAAAAAAAQAAAQgAAAAAAAAAAAAAAAAAAAAAAJQAAAAAAAEgAAAACAAUAtCAA
ABwEAAABAAAAAQAABgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMwAgBPAAAA
AAAAAAKOaRgzIQIWmm8EAAAKcgEAAHAoBQAACiwNAheabwQAAAooBgAACgKOaRgzIQIWmm8EAAAKcgcAAHAoBQAACiwN
AheabwcAAAooBgAACioeAigIAAAK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AAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAwAAAAgNQAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAA= -----END CERTIFICATE-----

  • デコードBase64、ファイル"%tmp%\ToUpLower.exe" に使用されるコマンドライン
%__APPDIR__%certutil.exe -f -decode "%~dpnx0" "%tmp%\ToUpLower.exe"  2>nul >nul

申し訳ありませんが英語

2
It Wasn't Me