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-08-09 21:00
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Resolved] How to determine whether the input is Chinese or English? View 2,161 Replies 27
Floor 16 Posted 2008-09-21 07:44 ·  中国 江西 赣州 安远县 电信
银牌会员
★★★★
Credits 2,025
Posts 1,122
Joined 2007-09-05 20:15
18-year member
UID 96653
Gender Male
Status Offline
Originally posted by HAT at 2008-9-20 05:30 AM:
Then use the idea from floor 2
@echo off
setlocal enabledelayedexpansion
set /p "str=Please enter:"
set sum=0
:loop
set "char=%str:~0,1%"
for /f "skip=1 delims=:" ...


This doesn't work. No matter what is entered, the batch processing will exit

[ Last edited by tireless on 2008-9-20 at 01:33 PM ]
Floor 17 Posted 2008-09-21 08:13 ·  中国 江苏 苏州 电信
初级用户
★★
Credits 195
Posts 93
Joined 2006-10-28 08:20
19-year member
UID 68626
Gender Male
Status Offline
In the final analysis, it's just that the regular expression of findstr is too restrictive
Floor 18 Posted 2008-09-21 10:21 ·  中国 广东 广州 电信
银牌会员
★★★
永远的菜鸟
Credits 1,335
Posts 574
Joined 2007-11-27 12:50
18-year member
UID 103929
Gender Male
From 广西
Status Offline
How about trying this?
Modify it to support special characters:
@echo off
setlocal enabledelayedexpansion
:bgn
type nul>t_.txt
set "n="&set "count="
set /p str=Please enter:
:agn
>>t_.txt echo.!str:~,1!
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 10:27 AM ]
Floor 19 Posted 2008-09-21 10:36 ·  中国 江西 赣州 安远县 电信
银牌会员
★★★★
Credits 2,025
Posts 1,122
Joined 2007-09-05 20:15
18-year member
UID 96653
Gender Male
Status Offline
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.
Floor 20 Posted 2008-09-21 11:33 ·  中国 广东 广州 电信
银牌会员
★★★
永远的菜鸟
Credits 1,335
Posts 574
Joined 2007-11-27 12:50
18-year member
UID 103929
Gender Male
From 广西
Status Offline
```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 ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
tireless +8 2008-09-21 17:37
Floor 21 Posted 2008-09-21 11:34 ·  中国 重庆 九龙坡区 电信
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
The running result of the code on floor 15:
C:\Test>test.bat
Please enter: Bed head bright moon light, suspected is frost on the ground. Lift head to look at bright moon, lower head to think of hometown.
456

Can you post your test cases and test results for me to see?
Floor 22 Posted 2008-09-21 11:44 ·  中国 江西 赣州 安远县 电信
银牌会员
★★★★
Credits 2,025
Posts 1,122
Joined 2007-09-05 20:15
18-year member
UID 96653
Gender Male
Status Offline
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...
Floor 23 Posted 2008-09-21 11:53 ·  中国 广东 广州 电信
银牌会员
★★★
永远的菜鸟
Credits 1,335
Posts 574
Joined 2007-11-27 12:50
18-year member
UID 103929
Gender Male
From 广西
Status Offline
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 ]
Floor 24 Posted 2008-09-21 21:29 ·  中国 江西 赣州 电信
银牌会员
★★★★
Credits 2,025
Posts 1,122
Joined 2007-09-05 20:15
18-year member
UID 96653
Gender Male
Status Offline
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 ]
Floor 25 Posted 2008-09-21 22:07 ·  中国 四川 成都 电信
中级用户
★★
Credits 297
Posts 135
Joined 2006-10-21 12:00
19-year member
UID 67627
Gender Male
Status Offline
```
If %str%==/h 执行命令 & exit
...
if /i "%str:~,2%"=="/h"

Why is there a quote added at the back, but not at the front?
```
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
tireless +5 2008-09-22 09:10
Floor 26 Posted 2008-09-22 09:11 ·  中国 江西 赣州 安远县 电信
银牌会员
★★★★
Credits 2,025
Posts 1,122
Joined 2007-09-05 20:15
18-year member
UID 96653
Gender Male
Status Offline
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……
At this time, there should be no Hee hee…….

Please enter:(**) Hee hee
At this time, there should be no Hee hee.

Please enter:O(∩_∩)O Haha
At this time, there should be no O Haha.

Please enter:O(∩_∩)O
At this time, there should be no O.


What is the reason?

Test with the following code:

@echo off
:s
set /p str=Please enter:

if not defined str echo Undefined&goto :s
If "%str%"=="/h" echo Execute /h command&goto :s
If "%str%"=="/s" echo Execute /s command&goto :s
If "%str%"=="/r" echo Execute /r command&goto :s
if /i "%str:~,3%"=="/h " (
set str=%str:~3%
echo Execute /h command
goto showtext
)
if /i "%str:~,3%"=="/s " (
set str=%str:~3%
echo Execute /s command
)

:showtext
echo %str%
goto s


[ Last edited by tireless on 2008-9-21 at 02:52 PM ]
Floor 27 Posted 2008-09-22 11:45 ·  中国 广东 广州 电信
银牌会员
★★★
永远的菜鸟
Credits 1,335
Posts 574
Joined 2007-11-27 12:50
18-year member
UID 103929
Gender Male
From 广西
Status Offline
Try it?

@echo off
Setlocal Enabledelayedexpansion
:s
set "str="
set /p str=Please enter:
if not defined str echo Not defined&goto :s
If /i "!str!"=="/h" echo Execute /h command&goto :s
If /i "!str!"=="/s" echo Execute /s command&goto :s
If /i "!str!"=="/r" echo Execute /r command&goto :s
if /i "!str:~,3!"=="/h " (
set "str=!str:~3!"
echo Execute /h command
goto showtext
)
if /i "!str:~,3!"=="/s " (
set "str=!str:~3!"
echo Execute /s command
)
:showtext
echo !str!
goto s


[ Last edited by moniuming on 2008-9-22 at 12:03 PM ]
Floor 28 Posted 2008-09-22 12:18 ·  中国 江西 赣州 安远县 电信
银牌会员
★★★★
Credits 2,025
Posts 1,122
Joined 2007-09-05 20:15
18-year member
UID 96653
Gender Male
Status Offline
It's all right. Thanks to everyone for your patient help.
Forum Jump: