12.8.2   Text with 2-byte characters (Chinese, Korean, Japanese)

some TCL built-in functions may fail to handle texts containing 2-byte characters for JPN/CHN/TWN/KOR versions. Those built-in functions in TCL can only take texts in the UTF8 format. WebAccess handles texts in native code pages. Since UTF8 and native formats for the texts containing characters whose ASCII codes are less than 128 are identical, there should be no issues for those texts. However, errors may occur when texts containing 2-byte characters are passed into those built-in functions. In order for users to work around this issue, we added two ACTION commands,  TOUTF8 and TONATIVE, to WebAccess TCL script engine. Please note that there should be no issues arising when VB script and Java script are used to handle texts containing 2-byte characters.

The following example illustrate how to deal with 2-byte characters in TCL script for TWN version of WebAccess. The equivalent versions of VB script and Java script are also illustrated below for comparison. As you can see in these examples, it is more straightforward to handle 2-byte characters using VB script or Java script than TCL script.

 TCL script:

# use TOUTF8 to convert text in native code page to UTF8

# before passing into built-in string function

# and pass the returning result (which is 10) directly to

# ACTION command BWSPOOL

 

BWSPOOL [string length [TOUTF8 {1234567壓力值}]]

 

# use TOUTF8 to convert text in native code page to UTF8

# before passing into built-in string function

# and use TONATIVE to convert returning text back to native

# code page (which is 4567壓力值) for ACTION command BWSPOOL

 

BWSPOOL [TONATIVE [string range [TOUTF8 {1234567壓力值}] 3 end]]

 

# pass text in native code page directly to ACTION command

# SETVAL

 

SETVAL {t1=1234567壓力值}

VB script:

BWSPOOL Len("1234567壓力值")

BWSPOOL Mid("1234567壓力值", 4)

SETVAL "t1=1234567壓力值"

Java script:

BWSPOOL("1234567壓力值".length.toString());

BWSPOOL("1234567壓力值".substring(3));

SETVAL("t1=1234567壓力值");