|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
 『楼 主』:
小写字母转大写
使用 LLM 解释/回答一下
字母小写转大写,可以通过罗列 set str=%str:a=A%、set str=%str:b=B%……的方式来解决,但是,这是纯体力活,毫无技巧可言。以下演示代码能让你在把字母小写转换为大写的时候,不再做毫无乐趣可言的 复制+粘贴+修改 这一重复劳动:
@echo off
:: 稍微修改一下代码就可以实现大写转小写
set str1=abcdefghijklmnopqrstuvwxyz
set str2=ABCDEFGHIJKLMNOPQRSTUVWXYZ
:main
cls
set str=
set /p str= 请输入字符串(退出请直接按回车):
if not defined str exit
cls
echo.
echo 转换前:"%str%"
echo.
for /l %%i in (0,1,25) do (
call set char1=%%str1:~%%i,1%%
call set char2=%%str2:~%%i,1%%
call :change
)
echo ____________________________________________
echo.
echo 转换后:"%str%"
echo.
echo 按任意键进行下一次演示...
pause>nul
goto main
:change
call set "str=%%str:%char1%=%char2%%%"
goto :eof
Lowercase letters to uppercase can be solved by listing methods like set str=%str:a=A%, set str=%str:b=B%..., but this is purely manual work with no skill involved. The following demo code allows you to no longer do the repetitive labor of copy + paste + modify that is unfun when converting lowercase letters to uppercase:
@echo off
:: A little modification of the code can realize uppercase to lowercase
set str1=abcdefghijklmnopqrstuvwxyz
set str2=ABCDEFGHIJKLMNOPQRSTUVWXYZ
:main
cls
set str=
set /p str= Please enter the string (press Enter directly to exit):
if not defined str exit
cls
echo.
echo Before conversion: "%str%"
echo.
for /l %%i in (0,1,25) do (
call set char1=%%str1:~%%i,1%%
call set char2=%%str2:~%%i,1%%
call :change
)
echo ____________________________________________
echo.
echo After conversion: "%str%"
echo.
echo Press any key to carry out the next demonstration...
pause>nul
goto main
:change
call set "str=%%str:%char1%=%char2%%%"
goto :eof
此帖被 +7 点积分 点击查看详情 评分人:【 tao0610 】 | 分数: +2 | 时间:2007-1-17 07:08 | 评分人:【 redtek 】 | 分数: +5 | 时间:2007-1-18 04:25 |
|
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2007-1-17 07:01 |
|
|
tao0610
高级用户
    朦胧的世界
积分 579
发帖 218
注册 2006-10-24
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
不错,不过还是习惯用Ultraedit转换.
Not bad, but still used to converting with Ultraedit.
|

认识自己,降伏自己,改变自己,才能改变别人! |
|
2007-1-17 07:08 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
好像不用这么复杂,一句for就搞定:
@echo off
:main
cls
set str=
set /p str= 请输入字符串(退出请直接按回车):
if not defined str exit
cls
echo.
echo 转换前:"%str%"
for %%i 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 call set str=%%str:%%i=%%i%%
echo ____________________________________________
echo.
echo 转换后:"%str%"
echo.
echo 按任意键进行下一次演示...
pause>nul
goto main
大转小改一下(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)就OK
Last edited by zh159 on 2007-1-16 at 08:54 PM ]
It seems it doesn't need to be so complicated, just a single for can handle it:
@echo off
:main
cls
set str=
set /p str= Please enter the string (press Enter directly to exit):
if not defined str exit
cls
echo.
echo Before conversion: "%str%"
for %%i 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 call set str=%%str:%%i=%%i%%
echo ____________________________________________
echo.
echo After conversion: "%str%"
echo.
echo Press any key to perform the next demonstration...
pause>nul
goto main
Just change it a bit to (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) and it's okay
Last edited by zh159 on 2007-1-16 at 08:54 PM ]
此帖被 +9 点积分 点击查看详情 评分人:【 namejm 】 | 分数: +4 | 时间:2007-1-17 10:00 | 评分人:【 redtek 】 | 分数: +5 | 时间:2007-1-18 04:25 |
|
|
|
2007-1-17 09:53 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
3楼充分利用了替换语句不区分大小写的特点,巧妙。
The third floor made full use of the feature that replacement statements are case-insensitive, which is clever.
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2007-1-17 09:59 |
|
|
redtek
金牌会员
     
积分 2902
发帖 1147
注册 2006-9-21
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
1楼和3楼代码的两种不同解决方法太精彩了~:)))
Last edited by redtek on 2007-1-16 at 09:08 PM ]
The solutions for the codes in the 1st floor and the 3rd floor are so wonderful~ : ) ) )
Last edited by redtek on 2007-1-16 at 09:08 PM ]
|

Redtek,一个永远在网上流浪的人……
_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._ |
|
2007-1-17 10:07 |
|
|
tashaxin
初级用户
 
积分 99
发帖 30
注册 2007-1-19
状态 离线
|
|
2007-1-20 08:20 |
|
|
greenworld
初级用户
 
积分 86
发帖 45
注册 2007-7-26
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
多谢LZ和3 楼的老大,强啊,学习了.......
Thanks to LZ and the boss on the 3rd floor, it's amazing, I've learned...
|
|
2007-9-15 21:48 |
|
|
106942397
初级用户
 
积分 29
发帖 15
注册 2008-4-23
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
不知为了什么搞那复杂呢?
setlocal ENABLEDELAYEDEXPANSION
set /p str=请输入字符串(退出请直接按回车):
for /l %%l in (0,1,100) do (
call set s%%l=!str:~%%l,1!
set Q=!s%%l!
for %%i 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 (
if /i !Q!==%%i set/p=%%i<nul
)
if "!Q!"=="" goto :Q1
)
:Q1
ECHO\
%0
这样可以吗?
Last edited by 106942397 on 2008-5-11 at 09:29 PM ]
Why make it so complicated for no reason?
setlocal ENABLEDELAYEDEXPANSION
set /p str=Please enter the string (press Enter directly to exit):
for /l %%l in (0,1,100) do (
call set s%%l=!str:~%%l,1!
set Q=!s%%l!
for %%i 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 (
if /i !Q!==%%i set/p=%%i<nul
)
if "!Q!"=="" goto :Q1
)
:Q1
ECHO\
%0
Is this okay?
Last edited by 106942397 on 2008-5-11 at 09:29 PM ]
|
|
2008-5-11 17:10 |
|
|
26933062
银牌会员
    
积分 2268
发帖 879
注册 2006-12-19
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
呵呵,8楼 请你输入 abcd 然后运行你的代码和3楼的代码 对比一下结果。
再说了,3楼的比你的复杂吗?
Hehe, 8th floor. Please input abcd and then run your code and compare the results with the code on the 3rd floor. Besides, is the code on the 3rd floor more complicated than yours?
|

致精致简! |
|
2008-5-11 17:33 |
|
|
106942397
初级用户
 
积分 29
发帖 15
注册 2008-4-23
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
大小写互换
setlocal ENABLEDELAYEDEXPANSION
set /p str=请输入字符串(退出请直接按回车):
for /l %%l in (0,1,100) do (
call set s%%l=!str:~%%l,1!
set Q=!s%%l!
for %%i 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 (
for %%k 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 (
if !Q!==%%i if /i !Q!==%%k set/p=%%k<nul
if !Q!==%%k if /i !Q!==%%i set/p=%%i<nul
))
if "!Q!"=="" goto :Q1
)
:q1
echo\
%0
Last edited by 106942397 on 2008-5-11 at 09:30 PM ]
Case Conversion
setlocal ENABLEDELAYEDEXPANSION
set /p str=Please enter the string (press Enter directly to exit):
for /l %%l in (0,1,100) do (
call set s%%l=!str:~%%l,1!
set Q=!s%%l!
for %%i 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 (
for %%k 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 (
if !Q!==%%i if /i !Q!==%%k set/p=%%k<nul
if !Q!==%%k if /i !Q!==%%i set/p=%%i<nul
))
if "!Q!"=="" goto :Q1
)
:q1
echo\
%0
Last edited by 106942397 on 2008-5-11 at 09:30 PM ]
|
|
2008-5-11 21:24 |
|
|
olslyang
新手上路

积分 4
发帖 2
注册 2008-6-20 来自 河北保定
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
老大,那个罗列的地方我看不懂,能不能给讲一下!不明白那个替换语句的用法!
str=%%str:%%i=%%i%%这一段我理解不了,有高人给指点一下不!!
我的QQ 362998909
Boss, I can't understand the part that's listed. Can you explain it? I don't understand the usage of that replacement statement!
I can't understand the part str=%%str:%%i=%%i%%. Is there any expert to give me some pointers!
My QQ 362998909
|
|
2008-6-20 22:36 |
|
|
olslyang
新手上路

积分 4
发帖 2
注册 2008-6-20 来自 河北保定
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
老大,那个罗列的地方我看不懂,能不能给讲一下!不明白那个替换语句的用法!
str=%%str:%%i=%%i%%这一段我理解不了,有高人给指点一下不!!
我的QQ 362998909
Boss, I can't understand the place listed. Can you explain it! I don't understand the usage of that replacement statement!
I can't understand the part str=%%str:%%i=%%i%%. Is there any expert to give some guidance!
My QQ 362998909
|
|
2008-6-20 22:36 |
|
|
moniuming
银牌会员
     永远的菜鸟
积分 1335
发帖 574
注册 2007-11-27 来自 广西
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
Originally posted by olslyang at 2008-6-20 22:36:
老大,那个罗列的地方我看不懂,能不能给讲一下!不明白那个替换语句的用法!
str=%%str:%%i=%%i%%这一段我理解不了,有高人给指点一下不!!
我的QQ 362998909
"变量延迟"
这样应该可以看得懂了吧:
call set str=%%str:%%i=%%i%%
Originally posted by olslyang at 2008-6-20 22:36:
Boss, I can't understand the part that lists things. Can you explain it to me! I don't understand the usage of that replacement statement!
I can't understand the part "str=%%str:%%i=%%i%%". Is there any expert to give some guidance!
My QQ 362998909
"Variable delay"
Maybe this can be understood:
call set str=%%str:%%i=%%i%%
|
|
2008-6-20 23:08 |
|