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-07-16 18:02
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to verify whether an input string contains double-byte characters View 2,981 Replies 15
Original Poster Posted 2008-01-04 20:20 ·  中国 广东 广州 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
As the title says. To expand on that, how can I search for and identify Chinese content in text?
Floor 2 Posted 2008-01-04 20:28 ·  中国 广东 广州 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
I’ve been researching this problem for a year. If you don’t believe me, search for my first post, hehe
Floor 3 Posted 2008-01-04 20:34 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline
o_O

Does it have to be pure batch processing?

[ Last edited by lxmxn on 2008-1-4 at 08:36 PM ]
Floor 4 Posted 2008-01-04 20:45 ·  中国 广西 玉林 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
First use character substring extraction to get a single character, then use your (echo string&echo.)|findstr /o ".*" to determine whether it is two bytes
(use character substring extraction to determine the number of characters, then use (echo string&echo.)|findstr /o ".*" to determine the number of bytes; if they are equal, then it does not contain double-byte characters)

input:Chinese
4


input:English
7


input:Chinese+English
12
Floor 5 Posted 2008-01-04 20:56 ·  中国 广西 玉林 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline

@echo off
set/p input=input:
set str=%input%

:loop
set str=%str:~1%
set/a n+=1
if not "%str%" == "" goto loop

for /f "skip=1 delims=:" %%i in ('^(echo "%input%"^&echo.^)^|findstr /o ".*"') do set/a l=%%i-5
if %n% == %l% (
echo String %input% does not contain double-byte characters
) else (
echo String %input% contains double-byte characters
)
pause>nul
exit


[ Last edited by zh159 on 2008-1-4 at 08:58 PM ]
Floor 6 Posted 2008-01-04 21:16 ·  中国 广东 广州 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
zh159
Hehe, I also only discovered findstr's o parameter while researching this, but this makes the code a bit too long, so I wanted to ask whether there’s any other method
lxmxn
A somewhat simpler VBS script would also be fine
Floor 7 Posted 2008-01-04 21:57 ·  中国 重庆 电信
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
A long time ago a moderator taught us a method:
After reading the first character, first use batch processing to determine whether it is a space. If it is not a space, then use:
echo %x%>3.txt and then check whether the file size of 3.txt is one byte or two bytes to determine whether it is a Chinese character.


Now there is also the findstr /o method

Looking forward to an even simpler method ^_^
Floor 8 Posted 2008-01-04 23:13 ·  中国 浙江 杭州 电信
高级用户
★★
Credits 537
Posts 219
Joined 2007-08-04 09:43
18-year member
UID 94620
Gender Male
From 杭州--半山
Status Offline
echo 望大师,傅.看见fdg|awk "{a=gsub(/[\x80-\xff]/,\"\");print a/2\" Chinese characters\"}"

6 Chinese characters
Floor 9 Posted 2008-01-05 00:16 ·  中国 广西 玉林 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
Originally posted by everest79 at 2008-1-4 21:16:
zh159
Hehe, I also only discovered findstr's o parameter while researching this, but this makes the code a bit too long, so I wanted to ask whether there’s any other method
lxmxn
A somewhat simpler VBS script would also be fine


A VBS script wouldn’t be much simpler either:
@echo off
set/p input=:

>ascw.vbs echo Wscript.echo ascw(wscript.arguments(0))

for /f %%i in ('"cscript //nologo ascw.vbs %input%"') do (
if %%i leq 255 (
echo %input% is not a double-byte character
) else (
echo %input% is a double-byte character
)
)
pause
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
everest79 +15 2008-01-05 00:43
Floor 10 Posted 2008-01-05 00:59 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline
To zh159:
What do you input in this case?
:ok我
ok我 is not a double-byte character
Press any key to continue . . .
Floor 11 Posted 2008-01-05 01:11 ·  中国 广西 玉林 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
ascw can only process characters one by one; to determine a whole sentence you need other statements to work with it
So in my post #9 I only wrote “is not a double-byte character / is a double-byte character”, and not “contains or does not contain double-byte characters”
Floor 12 Posted 2008-01-05 01:21 ·  中国 广西 玉林 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
To determine a string:
@echo off
set/p input=:

>ascw.vbs echo str=wscript.arguments(0):result="does not":for i=1 to len(str):if ascw(mid(str,i,1))^>255 then:result="":exit for:end if:next:Wscript.echo result^&" contain double-byte characters"

for /f %%i in ('"cscript //nologo ascw.vbs %input%"') do echo %input% %%i
pause
Floor 13 Posted 2008-01-05 17:49 ·  中国 四川 成都 教育网
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Floor 14 Posted 2008-01-05 20:17 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
VBS can use regular expressions to determine character types, but I still don’t know how -_-|||
Floor 15 Posted 2008-01-05 20:22 ·  中国 广东 广州 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
Is there a more complete one? I can’t imitate it from just a single line
Forum Jump: