|
fornever
初级用户
 
积分 98
发帖 35
注册 2006-1-14
状态 离线
|
『楼 主』:
如何过滤变量中指定的字符[已解决]
使用 LLM 解释/回答一下
我想要实现的功能是在用户输入任意字符后过滤掉指定的字符
或者是指定使用的字符类型
请高手指教!
Last edited by fornever on 2006-9-16 at 22:03 ]
The function I want to implement is to filter out specified characters or specify the type of characters used after the user enters any character. Please give instructions, experts!
Last edited by fornever on 2006-9-16 at 22:03 ]
|
|
2006-8-30 21:41 |
|
|
NaturalJ0
银牌会员
    
积分 1181
发帖 533
注册 2006-8-14
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
把 var 分两段
第一段是第一个字符,第二段是后面所有剩余的。
然后判断第一个字符是否要过滤。。。
然后判断剩下的字符串是否为空,如果不是就 GOTO 回上去继续循环。
Split the var into two parts. The first part is the first character, and the second part is all the remaining characters. Then judge whether the first character needs to be filtered... Then judge whether the remaining string is empty. If it is not empty, GOTO back to continue the loop.
|
|
2006-8-30 21:51 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
Re fornever:
过滤掉输入的字符是什么意思?就是在某个文本中把输入的字符删掉么?不明白你想做什么操作。
Re fornever:
What does it mean to filter out the input characters? Does it mean deleting the input characters in a certain text? I don't understand what operation you want to do.
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-8-30 22:51 |
|
|
fornever
初级用户
 
积分 98
发帖 35
注册 2006-1-14
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
是这样,比如用copy con h.txt命令或者set /p 命令让用户输入任意字符,然后我在后台过滤掉指定的字符,也不是过滤,就是提示说哪个哪个字符不准使用.总之是要识别某种字符吧!偶语文ci,还原谅!~
re:NaturalJ0
在想如何分割一个字符串,包括数字字母和n多的符号,或者说是 规定只能用某种类型的字符,比如规定只能用字母和数字,
要怎么样实现?
或者借助第三方工具?
This is like, for example, using the command copy con h.txt or the set /p command to let the user input any characters, and then I filter out specified characters in the background, or it's not filtering, just prompt that which character is not allowed to be used. In short, I need to identify a certain kind of character! Oh, my Chinese is poor, please forgive me!~
re:NaturalJ0
Wondering how to split a string, including numbers, letters, and many symbols, or say, specifying that only a certain type of characters can be used, such as specifying that only letters and numbers can be used,
How to implement it?
Or rely on third-party tools?
|
|
2006-8-31 21:21 |
|
|
NaturalJ0
银牌会员
    
积分 1181
发帖 533
注册 2006-8-14
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
set /p var="请用户输入:"
%var:~0,1% 这表示的是变量 var 的第一个字符
%var:~1% 这表示变量 var 除第一个字符外的后面所有字符
分段后你可以再做赋值或比较什么的,可以再用这个方法对剩下的字符串再取第一个字符。后面再怎么做,我想你自己会的吧。
set /p var="Please enter from user: "
%var:~0,1% This means the first character of variable var
%var:~1% This means all characters after the first character of variable var
After segmenting, you can do assignment or comparison, etc., and you can use this method to take the first character of the remaining string again. What to do next, I think you will know it yourself.
|
|
2006-8-31 21:45 |
|
|
fornever
初级用户
 
积分 98
发帖 35
注册 2006-1-14
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
呵呵.刚学会在看回复前,不过还是谢谢哈!
批处理真的是博大精深,敬!
想想还是现在写一下代码:
set /p var=请输入:
:start
if "%var:~0,1%"=="?" goto error
if "%var:~0,1%"==">" goto error
if "%var:~0,1%"=="<" goto error
if "%var:~0,1%"=="|" goto error
:: if "%var:~0,1%"=="添加过滤的字符" goto error
if "var"=="" goto next
set var=%var:~1%
goto start
:next
echo succeed!
goto end
:error
echo error!
:end
再次感谢帮助过的朋友!
Hehe. Just learned to check the reply before, but still thank you!
Batch processing is really profound, respect!
Think it's still write the code now:
set /p var=Please enter:
:start
if "%var:~0,1%"=="?" goto error
if "%var:~0,1%"==">" goto error
if "%var:~0,1%"=="<" goto error
if "%var:~0,1%"=="|" goto error
:: if "%var:~0,1%"=="Add filtered characters" goto error
if "var"=="" goto next
set var=%var:~1%
goto start
:next
echo succeed!
goto end
:error
echo error!
:end
Thank you again to the friends who helped!
|
|
2006-8-31 22:23 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
批处理并不能检测所有的字符,碰到敏感字符如|、>、<等等就会自动退出的。
Batch processing can't detect all characters. When it encounters sensitive characters like |, >, <, etc., it will automatically exit.
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-8-31 23:51 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
|
2006-9-1 12:55 |
|
|
fornever
初级用户
 
积分 98
发帖 35
注册 2006-1-14
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
...那用^符号可以吗?
其实我的目的是过滤掉那些不允许做文件名的字符
...Can the ^ symbol be used? Actually, my purpose is to filter out those characters that are not allowed to be used as file names
|
|
2006-9-1 18:36 |
|
|
fornever
初级用户
 
积分 98
发帖 35
注册 2006-1-14
状态 离线
|
『第 10 楼』:
关于fingstr命令
使用 LLM 解释/回答一下
其实还是上次的问题,不过今次不同的是要限制
限制set /p 后用户输入的字符为数字,大小写字母和特定的几个特殊符号
或者只限制某个类型的也可以!
Actually, it's still the previous question, but this time the difference is that we need to restrict the characters entered by the user after set /p to be numbers, uppercase and lowercase letters, and a few specific special symbols. Or it's also okay to restrict only one type!
|
|
2006-9-4 05:19 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
fingstr应该是findstr的笔误。
上次?上次的在哪?如果不是有心人,没人会关注他人的上次发的究竟是什么帖子。呵呵,你的要求我看得一头雾水。
fingstr should be a typo of findstr.
Last time? Where was the last time? If it's not someone who cares, no one will pay attention to what post others posted last time. Hehe, your requirement makes me confused.
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-9-5 07:18 |
|
|
fornever
初级用户
 
积分 98
发帖 35
注册 2006-1-14
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
对不起 确实是
http://www.cn-dos.net/forum/viewthread.php?tid=22897&fpage=1&highlight=
所谓的上次
意思是在用户输入字符串后用if 和findstr判断输入中是否有限制的字符
我想用findstr 限制输入的数据类型 为 大小写字母和数字
code:
set /p input:
::此处写findstr限制的%input:%类型
if ....
::此句if判断是否有不允许的字符类型,比如某些符号
I'm sorry, it's indeed
http://www.cn-dos.net/forum/viewthread.php?tid=22897&fpage=1&highlight=
The so-called last time
It means using if and findstr to judge whether there are restricted characters in the input after the user enters the string
I want to use findstr to restrict the data type of the input to uppercase and lowercase letters and numbers
code:
set /p input:
::Write the %input:% type restricted by findstr here
if ....
::This if statement judges whether there are disallowed character types, such as some symbols
|
|
2006-9-5 22:34 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
|
2006-9-6 02:28 |
|
|
9527
银牌会员
     努力做坏人
积分 1185
发帖 438
注册 2006-8-28 来自 北京
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
findstr "^[a-z][A-Z]*$" 判断纯字母
findstr "^[0-9]*$" 判断纯数字
@echo off
set/p aa=Enter your code:
echo %aa%|findstr "^[a-z][A-Z]*$"||echo ERROR!!!
随便写了一下,判断纯字母,不知道楼主是否是这个意思???
findstr "^*$" Judge pure letters
findstr "^*$" Judge pure numbers
@echo off
set/p aa=Enter your code:
echo %aa%|findstr "^*$"||echo ERROR!!!
Just wrote it casually, to judge pure letters, I wonder if the original poster means this???
|

我今后在论坛的目标就是做个超级坏人!!! |
|
2006-9-6 02:53 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
贴一段findstr的用法出来,楼主可以模仿着写个限制输入类型的代码出来:
FINDSTR正则表达式的基本用法
1.findstr . 2.txt 或 Findstr "." 2.txt
从文件2.txt中查找任意字符,不包括空字符或空行
====================
2.findstr .* 2.txt 或 findstr ".*" 2.txt
从文件2.txt中查找任意字符包括空行和空字符
====================
3.findstr "" 2.txt
从文件2.txt中查找包括数字0-9的字符串或行
====================
4.findstr "" 2.txt
从文件2.txt中查找包括任意字符的字符串或行
====================
5.findstr "" 2.txt
从文件2.txt中查找包括a b c e z y字母的字符串或行
====================
6.findstr "" 2.txt
从文件2.txt中查找小写字符a-f l-z的字符串,但不包含g h I j k这几个字母。
====================
7.findstr "MY" 2.txt
从文件2.txt中可以匹配 MahY , MbiY, MahY等…..
====================
8. ^和$符号的应用
^ 表示行首,"^step"仅匹配 "step hello world"中的第一个单词
$ 表示行尾,"step$"仅匹配 "hello world step"中最后一个单词
====================
9.finstr "" 2.txt
如果是纯数字的字符串或者行便过滤掉,例如2323423423 这样的字符串,如果是345hh888这样的形式就不成了。
====================
10.findstr "" 2.txt
同上,如果是纯字母的字符串或者行便过滤掉,例如 sdlfjlkjlksjdklfjlskdf这样的字符,如果是sdfksjdkf99999这样的形式,掺杂着数字就不成了
====================
11.*号的作用
前面已经说过了 ".*"表示搜索的条件是任意字符,*号在正则表达式中的作用不是任何字符,而是表示左侧字符或者表达式的重复次数,*号表示重复的次数为零次或者多次。
====================
12.findstr "^*$" 2.txt
这个是匹配找到的纯数字,例如 234234234234,如果是2133234kkjl234就被过滤掉了。
Findstr "^*$" 2.txt
这个是匹配找到的纯字母,例如 sdfsdfsdfsdf,如果是213sldjfkljsdlk就被过滤掉了
如果在搜索条件里没有*号,也就是说不重复左侧的搜索条件,也就是 那只能匹配字符串的第一个字符也只有这一个字符,因为有行首和行尾的限制,"^$"第一个字符如果是数字就匹配,如果不是就过滤掉,如果字符串是 9 就匹配,如果是98或者9j之类的就不可以了。
=====================
13. "\<…\>"这个表达式的作用
这个表示精确查找一个字符串,\<sss 表示字的开始位置,sss\>表示字的结束位置
echo hello world computer|findstr "\<computer\>"这样的形式
echo hello worldcomputer|findstr "\<computer\>" 这样的形式就不成了,他要找的是 "computer"这个字符串,所以不可以。
echo hello worldcomputer|findstr ".*computer\>"这样就可以匹配了
=====================
Here is the translation of the above content:
Post a section of the usage of findstr. The original poster can imitate to write a code to restrict the input type:
Basic Usage of FINDSTR Regular Expressions
1. findstr . 2.txt or Findstr "." 2.txt
Find any characters from file 2.txt, excluding empty characters or blank lines
====================
2. findstr .* 2.txt or findstr ".*" 2.txt
Find any characters from file 2.txt including blank lines and empty characters
====================
3. findstr "" 2.txt
Find strings or lines including numbers 0-9 from file 2.txt
====================
4. findstr "" 2.txt
Find strings or lines including any characters from file 2.txt
====================
5. findstr "" 2.txt
Find strings or lines including letters a, b, c, e, z, y from file 2.txt
====================
6. findstr "" 2.txt
Find strings of lowercase characters a-f and l-z from file 2.txt, but do not include letters g, h, I, j, k.
====================
7. findstr "MY" 2.txt
Can match MahY, MbiY, MahY, etc. in file 2.txt…..
====================
8. Application of ^ and $ symbols
^ means the beginning of a line, " ^step" only matches the first word in "step hello world"
$ means the end of a line, "step$" only matches the last word in "hello world step"
====================
9. finstr "" 2.txt
If it is a pure digital string or line, filter it out. For example, a string like 2323423423, if it is in the form of 345hh888, it is not.
====================
10. findstr "" 2.txt
Same as above, if it is a pure letter string or line, filter it out. For example, a character like sdlfjlkjlksjdklfjlskdf, if it is in the form of sdfksjdkf99999, mixed with numbers, it is not.
====================
11. Role of * symbol
As mentioned earlier, ".*" means the search condition is any character. The role of * in regular expressions is not any character, but means the number of repetitions of the left character or expression. * means the number of repetitions is zero or more times.
====================
12. findstr "^*$" 2.txt
This matches pure numbers found, for example 234234234234, if it is 2133234kkjl234, it is filtered out.
Findstr "^*$" 2.txt
This matches pure letters found, for example sdfsdfsdfsdf, if it is 213sldjfkljsdlk, it is filtered out.
If there is no * sign in the search condition, that is, not repeating the left search condition, that is, , it can only match the first character of the string and only this character. Because of the restrictions of the beginning and end of the line, "^$" will match if the first character is a number, and filter out if it is not. If the string is 9, it matches; if it is 98 or 9j, etc., it is not possible.
=====================
13. The role of "\<…\>" expression
This means to accurately find a string. \<sss means the start position of a word, and sss\> means the end position of a word.
echo hello world computer|findstr "\<computer\>" such form
echo hello worldcomputer|findstr "\<computer\>" such form is not, it wants to find the string "computer", so it is not.
echo hello worldcomputer|findstr ".*computer\>" this can match
=====================
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-9-6 02:57 |
|