![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-08-10 14:57 |
47,811 topics / 349,897 posts / today 0 new / 48,255 members |
| DOS批处理 & 脚本技术(批处理室) » How to filter specified characters in a variable [Solved] |
| Printable Version 8,789 / 31 |
| Floor1 fornever | Posted 2006-08-30 21:41 |
| 初级用户 Posts 35 Credits 98 | |
|
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 ] |
|
| Floor2 NaturalJ0 | Posted 2006-08-30 21:51 |
| 银牌会员 Posts 533 Credits 1,181 | |
|
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.
|
|
| Floor3 namejm | Posted 2006-08-30 22:51 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
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. |
|
| Floor4 fornever | Posted 2006-08-31 21:21 |
| 初级用户 Posts 35 Credits 98 | |
|
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? |
|
| Floor5 NaturalJ0 | Posted 2006-08-31 21:45 |
| 银牌会员 Posts 533 Credits 1,181 | |
|
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. |
|
| Floor6 fornever | Posted 2006-08-31 22:23 |
| 初级用户 Posts 35 Credits 98 | |
|
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! |
|
| Floor7 namejm | Posted 2006-08-31 23:51 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
Batch processing can't detect all characters. When it encounters sensitive characters like |, >, <, etc., it will automatically exit.
|
|
| Floor8 vkill | Posted 2006-09-01 12:55 |
| 金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽 | |
| Floor9 fornever | Posted 2006-09-01 18:36 |
| 初级用户 Posts 35 Credits 98 | |
|
...Can the ^ symbol be used? Actually, my purpose is to filter out those characters that are not allowed to be used as file names
|
|
| Floor10 fornever | Posted 2006-09-04 05:19 |
| 初级用户 Posts 35 Credits 98 | |
|
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!
|
|
| Floor11 namejm | Posted 2006-09-05 07:18 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
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. |
|
| Floor12 fornever | Posted 2006-09-05 22:34 |
| 初级用户 Posts 35 Credits 98 | |
|
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 |
|
| Floor13 vkill | Posted 2006-09-06 02:28 |
| 金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽 | |
| Floor14 9527 | Posted 2006-09-06 02:53 |
| 银牌会员 Posts 438 Credits 1,185 From 北京 | |
|
findstr "^[a-z][A-Z]*$" Judge pure letters
findstr "^[0-9]*$" Judge pure numbers @echo off set/p aa=Enter your code: echo %aa%|findstr "^[a-z][A-Z]*$"||echo ERROR!!! Just wrote it casually, to judge pure letters, I wonder if the original poster means this??? |
|
| Floor15 namejm | Posted 2006-09-06 02:57 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
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: |
|
| 1 2 3 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |