链接: https://pan.baidu.com/s/1H6kqbUEzdBtG8kUBafFrtA?pwd=ic4k复制代码
- @ECHO OFF
- Rem XXXXXXXXXXXXXXXXXXXXXXXX 参数整理 XXXXXXXXXXXXXXXXXXXXXXXX
- SET "Parameter=%*"
- IF NOT DEFINED Parameter (
- CALL :HELP
- PAUSE 1>NUL
- CALL :EXPORT && EXIT /B 1
- ) ELSE (
- ECHO [%Parameter%] | FIND /I "?" 1>NUL && ( CALL :HELP && CALL :EXPORT && EXIT /B 1 )
- )
- SET "Parameter1="&&SET "Parameter2="&&SET "Parameter3="&&SET "Parameter4="&&SET "Parameter5="
- :Parameter
- SET "Parameter=%~1"
- REM ECHO 00140-[%Parameter%]
- IF NOT DEFINED Parameter GOTO EndParameter
- %Parameter1% IF /I "%Parameter:~0,7%" EQU "Chinese" ( SET "Chinese=%Parameter:~8%" && SET "Parameter1=Rem" ) && GOTO IFParameter
- %Parameter2% IF /I "%Parameter:~0,6%" EQU "Return" ( SET "Return=%Parameter:~7%" && SET "Parameter2=Rem" ) && GOTO IFParameter
- %Parameter3% IF /I "%Parameter:~0,8%" EQU "WordBook" ( SET "WordBook=%Parameter:~9%" && SET "Parameter3=Rem" ) && GOTO IFParameter
- %Parameter4% IF /I "%Parameter:~1%" EQU "QP" ( SET "QP=%Parameter:~1%" && SET "Parameter4=Rem" ) && GOTO IFParameter
- %Parameter5% IF /I "%Parameter:~1%" EQU "SZ" ( SET "SZ=%Parameter:~1%" && SET "Parameter5=Rem" ) && GOTO IFParameter
- ECHO. && CALL :ERROR "%Parameter%" && CALL :EXPORT && EXIT /B 12
- :IFParameter
- SHIFT /1
- GOTO Parameter
- :EndParameter
- IF DEFINED QP ( IF DEFINED SZ ( CALL :ERROR "QO与SZ不可同时存在" &&CALL :EXPORT && EXIT /B 13 & EXIT /B 13 ) )
- ::测试时显显示各参数的值
- IF 1 LSS 0 (
- ECHO 1.中文字符串 Chinese=%Chinese%
- ECHO 2.输出返回值 Return=%Return%
- ECHO 3.字典路径 WordBook=%WordBook%
- ECHO 4.QP: [%QP%]
- ECHO 5.SZ: [%SZ%]
- PAUSE
- )
- Rem XXXXXXXXXXXXXXXXXXXXXXXX 准备 XXXXXXXXXXXXXXXXXXXXXXXX
- Rem 字典路径
- :WORDBOOK0
- IF EXIST %WORDBOOK% GOTO WORDBOOK1
- ECHO.&&ECHO.&&ECHO.&&ECHO.
- ECHO.请输入《字典》所在路径:
- ECHO.[Q]:退出
- ECHO.
- SET "WORDBOOK="
- SET /P WORDBOOK=
- IF /I "%WORDBOOK%" EQU "Q" ( CALL :EXPORT && EXIT /B 1 & EXIT /B 1 )
- IF EXIST "%WORDBOOK%" GOTO WORDBOOK1
- IF EXIST "%WORDBOOK%.TXT" ( SET "WORDBOOK=%WORDBOOK%.TXT" && GOTO WORDBOOK1 )
- ECHO.
- CALL :ERROR "输入错误或没有找到字典"
- ECHO.
- GOTO WORDBOOK0
- :WORDBOOK1
- Rem XXXXXXXXXXXXXXXXXXXXXXXX 中文转拼音 XXXXXXXXXXXXXXXXXXXXXXXX
- IF DEFINED SZ ( SET "REMSZ=" ) ELSE ( SET "REMSZ=REM" )
- :StartMain
- SET "VARIABLE=%Chinese:~,1%"
- IF /I "%VARIABLE%" EQU " " ( SET "OUTPUT= " && GOTO ENDOUTPUT3 )
- IF /I "%VARIABLE%" EQU " " ( SET "OUTPUT= " && GOTO ENDOUTPUT3 )
- IF NOT DEFINED Chinese GOTO EndMain
- FOR /F "EOL=; TOKENS=1,*" %%I IN ( 'TYPE %WORDBOOK%' ) DO (
- IF "%VARIABLE%" EQU "%%~I" (
- SET "OUTPUT=%%~J"
- REM 当条件成立后即退出此 “For %%I” 的循环?
- )
- )
- IF DEFINED OUTPUT GOTO ENDOUTPUT1
- ECHO 在字典中,没有找到“%VARIABLE%”的拼音
- ECHO 请手动输入该字的拼音:
- ECHO [回车]:跳过
- ECHO.
- SET "OUTPUT="
- SET /P OUTPUT=. %VARIABLE%:
- ECHO.
- IF NOT DEFINED OUTPUT GOTO ENDOUTPUT3
- :ENDOUTPUT1
- ECHO [%OUTPUT%] | FIND /I "&" 1>NUL || GOTO ENDOUTPUT2
- ECHO.
- ECHO 字符串 [ %Chinese% ] 中的“%VARIABLE%”为多音字,
- ECHO 请手动输入该字的拼音:
- ECHO [回车]:跳过
- ECHO.
- SET "OUTPUT="
- SET /P OUTPUT=. %VARIABLE%:
- ECHO.
- IF NOT DEFINED OUTPUT GOTO ENDOUTPUT3
- :ENDOUTPUT2
- %REMSZ% SET "OUTPUT=%OUTPUT:~0,1%"
- :ENDOUTPUT3
- SET "OPPY=%OPPY%%OUTPUT%"
- SET "OUTPUT="
- SET "Chinese=%Chinese:~1%"
- GOTO StartMain
- :EndMain
- REM ECHO -[%OPPY%]-
- SET "%Return%=%OPPY%"
- REM ECHO [%Return%][%OPPY%]
- CALL :EXPORT
- EXIT /B 0
- Rem XXXXXXXXXXXXXXXXXXXXXXXX 帮助 XXXXXXXXXXXXXXXXXXXXXXXX
- :HELP
- ECHO.
- ECHO CtoP.bat 汉字转拼音 by Bo (IBM) [20090424]
- ECHO 通过字典(WORDBOOK.txt)查找对应的拼音,
- ECHO 用户可以手动修改字典中的拼音
- ECHO 支持阿拉伯数字转拼音
- ECHO 遇到多音字或字典中未收录的文字,
- ECHO 程序会暂停执行,并要求用户手动输入
- ECHO.
- ECHO 用法:
- ECHO %~NX0 "Chinese-String" Return-Variable [WordBook-PATH] [/QP ^| /SZ]
- ECHO.
- ECHO 参数说明:
- ECHO.
- ECHO String: 中文字符串
- ECHO Variable:输出返回值变量
- ECHO PATH: 字典路径
- ECHO /QP: 全拼(默认)
- ECHO /SZ: 简拼(首字母)
- ECHO.
- ECHO 部分特殊字符及标点不支持
- ECHO.
- ECHO.
- GOTO :EOF
- REM ERRORLEVEL 0 正常执行转化后退出
- REM ERRORLEVEL 0 正常执行未转化退出
- REM ERRORLEVEL 11 参数不匹配
- REM ERRORLEVEL 12 QP 与 SZ 不可同时存在
- Rem XXXXXXXXXXXXXXXXXXXXXXXX 报错 XXXXXXXXXXXXXXXXXXXXXXXX
- :ERROR
- SET "ERRORNUM=%~1"
- ECHO.&&ECHO.
- COLOR 0C
- ECHO 错误:%ERRORNUM%
- ECHO.
- PAUSE
- ECHO.
- COLOR 1F
- GOTO :EOF
- Rem XXXXXXXXXXXXXXXXXXXXXXXX 出口 XXXXXXXXXXXXXXXXXXXXXXXX
- :EXPORT
- SET "Parameter="
- SET "Parameter1="
- SET "Parameter2="
- SET "Parameter3="
- SET "Parameter4="
- SET "Parameter5="
- SET "Chinese="
- SET "Return="
- SET "WordBook="
- SET "QP="
- SET "SZ="
- SET "ERRORNUM="
- SET "VARIABLE="
- SET "OPPY="
- ECHO.&&ECHO.
- GOTO :EOF
CtoP.bat 汉字转拼音 by Bo [20090424]
复制代码
- @echo off
- set /p input=请输入汉字:
- set "input=%input =%"
- set "input=%input =%"
- :lp
- for /f "tokens=2" %%a in ('findstr "%input:~,1%" wordbook.txt') do set /p=%%a <nul
- set "input=%input:~1%"&if defined input goto lp
- pause>nul
欢迎光临 批处理之家 (http://bathome.net./) | Powered by Discuz! 7.2 |