China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-07-03 15:02
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Convert lowercase letters to uppercase View 4,345 Replies 12
Original Poster Posted 2007-01-17 07:01 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
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
Recent Ratings for This Post ( 2 in total) Click for details
RaterScoreTime
tao0610 +2 2007-01-17 07:08
redtek +5 2007-01-18 04:25
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 2 Posted 2007-01-17 07:08 ·  中国 北京 朝阳区 联通
高级用户
★★
朦胧的世界
Credits 579
Posts 218
Joined 2006-10-24 04:29
19-year member
UID 67972
Status Offline
Not bad, but still used to converting with Ultraedit.

认识自己,降伏自己,改变自己
,才能改变别人!
Floor 3 Posted 2007-01-17 09:53 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
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 ]
Recent Ratings for This Post ( 2 in total) Click for details
RaterScoreTime
namejm +4 2007-01-17 10:00
redtek +5 2007-01-18 04:25
Floor 4 Posted 2007-01-17 09:59 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
The third floor made full use of the feature that replacement statements are case-insensitive, which is clever.
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 5 Posted 2007-01-17 10:07 ·  中国 北京 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
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,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 6 Posted 2007-01-20 08:20 ·  中国 广东 佛山 顺德区 电信
初级用户
Credits 99
Posts 30
Joined 2007-01-19 05:46
19-year member
UID 76980
Gender Male
Status Offline
Floor 7 Posted 2007-09-15 21:48 ·  中国 广东 广州 番禺区 电信
初级用户
Credits 86
Posts 45
Joined 2007-07-26 17:35
18-year member
UID 94082
Gender Male
Status Offline
Thanks to LZ and the boss on the 3rd floor, it's amazing, I've learned...
Floor 8 Posted 2008-05-11 17:10 ·  中国 广东 江门 电信
初级用户
Credits 29
Posts 15
Joined 2008-04-23 20:23
18-year member
UID 116742
Gender Male
Status Offline
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 ]
Floor 9 Posted 2008-05-11 17:33 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
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?
致精致简!
Floor 10 Posted 2008-05-11 21:24 ·  中国 广东 江门 新会区 电信
初级用户
Credits 29
Posts 15
Joined 2008-04-23 20:23
18-year member
UID 116742
Gender Male
Status Offline
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 ]
Floor 11 Posted 2008-06-20 22:36 ·  中国 内蒙古 包头 联通
新手上路
Credits 4
Posts 2
Joined 2008-06-20 22:13
18-year member
UID 120656
Gender Male
From 河北保定
Status Offline
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
Floor 12 Posted 2008-06-20 22:36 ·  中国 内蒙古 包头 联通
新手上路
Credits 4
Posts 2
Joined 2008-06-20 22:13
18-year member
UID 120656
Gender Male
From 河北保定
Status Offline
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
Floor 13 Posted 2008-06-20 23:08 ·  中国 广东 广州 广东金万邦科技投资有限公司(新一代数据中心)IDC机房(BGP)
银牌会员
★★★
永远的菜鸟
Credits 1,335
Posts 574
Joined 2007-11-27 12:50
18-year member
UID 103929
Gender Male
From 广西
Status Offline
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%%
Forum Jump: