![]() |
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-11-24 11:15 |
47,820 topics / 349,938 posts / today 0 new / 48,298 members |
| DOS批处理 & 脚本技术(批处理室) » [Resolved] How to determine whether the input is Chinese or English? |
| Printable Version 2,783 / 27 |
| Floor16 tireless | Posted 2008-09-21 07:44 |
| 银牌会员 Posts 1,122 Credits 2,025 | |
Originally posted by HAT at 2008-9-20 05:30 AM: |
|
| Floor17 metoo | Posted 2008-09-21 08:13 |
| 初级用户 Posts 93 Credits 195 | |
|
In the final analysis, it's just that the regular expression of findstr is too restrictive
|
|
| Floor18 moniuming | Posted 2008-09-21 10:21 |
| 银牌会员 Posts 574 Credits 1,335 From 广西 | |
|
How about trying this?
Modify it to support special characters: [ Last edited by moniuming on 2008-9-21 at 10:27 AM ] |
|
| Floor19 tireless | Posted 2008-09-21 10:36 |
| 银牌会员 Posts 1,122 Credits 2,025 | |
|
The calculation is incorrect. The result of "Bed head bright moon light, suspect is frost on the ground. Raise head to look at bright moon, lower head to think of hometown." is 240. The correct one should be 456.
|
|
| Floor20 moniuming | Posted 2008-09-21 11:33 |
| 银牌会员 Posts 574 Credits 1,335 From 广西 | |
|
```batch
@echo off setlocal enabledelayedexpansion :bgn del t_.txt 1>nul 2>nul set "n="&set "count=" set /p str=Please enter: :agn set st=!str:~,1! >>t_.txt echo.!st! if not "!str:~1!"=="" (set "str=!str:~1!"&goto :agn) >>t_.txt echo god for /f "delims=:" %%a in ('findstr /o .* t_.txt') do ( set /a "n+=1","m=n-1" set "_!n!=%%a" if !n! geq 2 ( call set /a "var=%%_!n!%%-%%_!m!%%" if !var! equ 4 (set /a count+=19) else (set /a count+=10) ) ) echo %count% goto :bgn ``` [ Last edited by moniuming on 2008-9-21 at 11:41 AM ] |
|
| Floor21 HAT | Posted 2008-09-21 11:34 |
| 版主 Posts 5,017 Credits 9,023 | |
|
The running result of the code on floor 15:
C:\Test>test.bat Can you post your test cases and test results for me to see? |
|
| Floor22 tireless | Posted 2008-09-21 11:44 |
| 银牌会员 Posts 1,122 Credits 2,025 | |
|
Uh, the code on the 15th floor is useful. The calculation is too slow. Last night I thought the batch processing didn't respond and closed it before the result came out...
|
|
| Floor23 moniuming | Posted 2008-09-21 11:53 |
| 银牌会员 Posts 574 Credits 1,335 From 广西 | |
|
After multiple tests, the 20th floor has passed various tests, and the efficiency is okay. Try it?
[ Last edited by moniuming on 2008-9-21 at 11:55 AM ] |
|
| Floor24 tireless | Posted 2008-09-21 21:29 |
| 银牌会员 Posts 1,122 Credits 2,025 | |
|
Final Integration...
The code on floor 20 is completely error-free. I want to add some command processing on the original basis, but there is something wrong with the code I wrote, so I need to trouble you again, and integrate them together. I want to perform these processes on the original basis: 1. Also display what is entered 2. After input, first make these judgments: If: Press Enter directly, then execute the command If the input is /h, then execute the command and exit If the input is /s, then execute the command and exit If the input is /r, then execute the command and exit Then judge the following: If it starts with /h, then intercept the characters after /h, and then execute the command If it starts with /s, then intercept the characters after /s, and then execute the command The following is the code I modified: ■: Original code on floor 20 ■: What I added @echo off setlocal enabledelayedexpansion :bgn del t_.txt 1>nul 2>nul set "n="&set "count=" set /p str=Please enter: if not defined str goto 11 If %str%==/h 执行命令 & exit If %str%==/s 执行命令 & exit If %str%==/r 执行命令 & exit if /i "%str:~,2%"=="/h" ( set str=%str:~2% 执行命令 goto settext ) if /i "%str:~,2%"=="/s" ( set str=%str:~2% 执行命令 ) :settext set Text=%str% :agn set st=!str:~,1! >>t_.txt echo.!st! if not "!str:~1!"=="" (set "str=!str:~1!"&goto :agn) >>t_.txt echo god for /f "delims=:" %%a in ('findstr /o .* t_.txt') do ( set /a "n+=1","m=n-1" set "_!n!=%%a" if !n! geq 2 ( call set /a "var=%%_!n!%%-%%_!m!%%" if !var! equ 4 (set /a count+=19) else (set /a count+=10) ) ) echo %count% echo %text% goto :bgn :11 ... The test result is that there will be an error if there is a space. (The error is not elsewhere, just in the part I added that the operation is interrupted) [ Last edited by tireless on 2008-9-21 at 01:53 AM ] |
|
| Floor25 zqz0012005 | Posted 2008-09-21 22:07 |
| 中级用户 Posts 135 Credits 297 | |
|
```
If %str%==/h 执行命令 & exit Why is there a quote added at the back, but not at the front? ``` |
|
| Floor26 tireless | Posted 2008-09-22 09:11 |
| 银牌会员 Posts 1,122 Credits 2,025 | |
Why is there a quote added later, but not earlier? After adding the quote, there is no problem with entering spaces. But there is another problem: Please enter:(*^__^*) Hee hee…… What is the reason? Test with the following code: [ Last edited by tireless on 2008-9-21 at 02:52 PM ] |
|
| Floor27 moniuming | Posted 2008-09-22 11:45 |
| 银牌会员 Posts 574 Credits 1,335 From 广西 | |
|
Try it?
[ Last edited by moniuming on 2008-9-22 at 12:03 PM ] |
|
| Floor28 tireless | Posted 2008-09-22 12:18 |
| 银牌会员 Posts 1,122 Credits 2,025 | |
|
It's all right. Thanks to everyone for your patient help.
|
|
| Prev 1 2 |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |