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-06-23 00:09
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to extract the numbers from the combination of <letters + numbers> View 3,744 Replies 18
Original Poster Posted 2006-12-28 04:59 ·  中国 湖南 郴州 电信
初级用户
Credits 66
Posts 28
Joined 2006-11-01 04:54
19-year member
UID 69099
Gender Male
Status Offline
Combination of letters and numbers.. For example, home001
How can I extract 001
Both letters and numbers are of unlimited length.
I don't know if batch processing can achieve it.
Hope experts can give guidance. No relevant information was found in the forum
Floor 2 Posted 2006-12-28 06:12 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Can numbers and letters possibly be mixed? Or are numbers one segment and letters another segment?
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 3 Posted 2006-12-28 06:19 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
I have seen one case where a dictionary is needed

setlocal enabledelayedexpansion
set /p a=..
set b=%a%
for /f %%i in (dict.txt) do set b=!b:%%i=!
Can't remember clearly
Floor 4 Posted 2006-12-28 06:28 ·  中国 湖南 郴州 电信
初级用户
Credits 66
Posts 28
Joined 2006-11-01 04:54
19-year member
UID 69099
Gender Male
Status Offline
Originally posted by namejm at 2006-12-28 06:12 AM:
  Can numbers and letters be mixed? Or are numbers one segment and letters another segment?

Yes. The front is letters. The back is numbers.
This is fixed.
Floor 5 Posted 2006-12-28 06:33 ·  中国 北京 联通
银牌会员
★★★
努力做坏人
Credits 1,185
Posts 438
Joined 2006-08-28 12:00
19-year member
UID 61449
From 北京
Status Offline
No matter whether your numbers and text are mixed, do it all, heh heh......
No special symbols were tested

@echo off&setlocal
set/p aa=Enter your text:
call :pp
echo %b%
goto :eof
:pp
:loop
if not defined aa goto :eof
echo %aa:~0,1%|findstr "">nul&&set b=%b%%aa:~0,1%
set aa=%aa:~1%&goto loop
goto :eof

But I feel this code is a bit bloated
[ Last edited by 9527 on 2006-12-28 at 06:34 AM ]
我今后在论坛的目标就是做个超级坏人!!!
Floor 6 Posted 2006-12-28 06:35 ·  中国 北京 朝阳区 联通
高级用户
★★
朦胧的世界
Credits 579
Posts 218
Joined 2006-10-24 04:29
19-year member
UID 67972
Status Offline
Just replace the letters directly without any modification!

认识自己,降伏自己,改变自己
,才能改变别人!
Floor 7 Posted 2006-12-28 06:36 ·  中国 北京 东城区 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
Wonderful!!! Appreciate ~~~
    Redtek,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 8 Posted 2006-12-28 06:41 ·  中国 甘肃 甘南藏族自治州 合作市 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
set "var=abc123 &^*"
echo "%var%"|sed "s/^\x22//;s/\x22$//;s/[a-z]//g"
Floor 9 Posted 2006-12-28 07:08 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Hehe, actually I just want to ask the original poster whether it's only to intercept a specified segment of numbers or to extract all numbers in the string. If it's just to extract all numbers, then it's much easier, just replace the letters with empty values. But it seems the original poster's intention is not like that.
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 10 Posted 2006-12-28 08:29 ·  中国 北京 顺义区 联通
银牌会员
★★★
努力做坏人
Credits 1,185
Posts 438
Joined 2006-08-28 12:00
19-year member
UID 61449
From 北京
Status Offline
Then please, moderator namejm, release the code that the original poster needs, so that we juniors can also learn more...
我今后在论坛的目标就是做个超级坏人!!!
Floor 11 Posted 2006-12-28 08:36 ·  中国 广西 南宁 联通
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
Originally posted by mouzeming at 2006-12-27 17:28:

Yes. The front is letters. The back is numbers.
This is fixed.

According to the original poster's statement, the data has letters in the front and numbers in the back, which is fixed, so moderator namejm doesn't need to worry about mixing letters and numbers

@echo off
set "var=abc123"
for %%n 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 var=%%var:%%n=%%
echo %var%
pause
Floor 12 Posted 2006-12-28 11:28 ·  中国 湖南 郴州 电信
初级用户
Credits 66
Posts 28
Joined 2006-11-01 04:54
19-year member
UID 69099
Gender Male
Status Offline
Thank you everyone.. I'll try it at the company tomorrow..

b=%b%%aa:~0,1%

set "var=abc123 &^*"
echo "%var%"|sed "s/^\x22//;s/\x22$//;s/[a-z]//g"

set var=%%var:%%n=%%
Floor 13 Posted 2006-12-28 11:46 ·  中国 广西 南宁 联通
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
The person on floor 8 needs the "sed" software.
Floor 14 Posted 2006-12-28 11:57 ·  中国 北京 东城区 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
Top~ Appreciate ~~~!!!
    Redtek,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 15 Posted 2006-12-28 21:59 ·  中国 辽宁 联通
银牌会员
★★★
Credits 1,212
Posts 464
Joined 2006-12-13 21:11
19-year member
UID 73417
Gender Male
Status Offline
There is an idea, I don't know if this method can be used when entering the password?
Forum Jump: