2021-06-21

Convertion To ASCII

This’s an initial verison for implementation to make convertion to ascii (Dec) for a character, note: the max string length couldn’t be over 128.

@ECHO OFF
@REM ------------------------------------------------------------------------------------------------------------------------
@REM  
@REM @Date:
@REM  @author jwang6
@REM
@REM  Purpose: Implementation to convert char variables to ASCII value for later use.
@REM ------------------------------------------------------------------------------------------------------------------------

setlocal EnableDelayedExpansion

@REM tv: test variable
set tv=d:/hello_world/

CALL :Conv_Char_To_Hex %tv%

GOTO :END





:Conv_Char_To_Hex
@REM make convertion to asiicc value from character type.
@REM CHARA_SET:This is a set of characters
SET CHARA_SET= ^^^!^"#$^%%^&'()*+,-./0123456789^:;^^^<=^^^>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^^^^_`abcdefghijklmnopqrstuvwxyz{^|}~
@REM MAX_FILE_PATH_LEN: Allow for PATH size of UNISON
@REM CHARA_SET_LEN:     Definition for characters set length
@REM CHAR_SRC:          Characters or String need to convert
@REM BASE:              Base character ' '(SP), others character asiicc offset caculation will base on it.
SET MAX_FILE_PATH_LEN=128
SET CHARA_SET_LEN=96
SET CHAR_SRC=%1
SET BASE=0x20

FOR /L %%i IN (0,1,%MAX_FILE_PATH_LEN%) DO (
    SET ch=!CHAR_SRC:~%%i,1!
    IF NOT ""=="!ch!" (
	@echo $:"!ch!"
		FOR /L %%j IN (0,1,%CHARA_SET_LEN%) DO (
		  IF "!ch!"=="!CHARA_SET:~%%j,1!"  SET /A CH_ASCII=BASE+%%j && echo !CH_ASCII! || GOTO :BUILDWITHERROR)
		)
    )
)
GOTO :EOF

:END

:BUILDWITHERROR
EXIT /B 1
ECHO ***************************** BUILD WITH ERROR %errorlevel% *******************************

test result as following:
2021-06-21

上一篇:Envi 缺少 ROI from ASCII


下一篇:[1006]python之string模块常量:数字,26个字母,标点符号,空白