× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



On 16-Mar-2015 07:00 -0500, Marco Benetti wrote:
On a 7.2 machine I can use the new keyword CCSID(*CHAR:*UTF8),
defining my char variables with CCSID 1208.
It seems to me that %subst does not substring characters, but bytes.

I'm running some tests, and I obtain these results.
My job CCSID is 1144.
I assign the string '€' (euro sign) to my utf-8 variable CHAR10.

H DECEDIT(*JOBRUN) DATEDIT(*DMY/) DFTACTGRP(*NO) ACTGRP(*CALLER)
H OPTION(*NODEBUGIO)
H CCSID(*UCS2: 1200)
H CCSID(*CHAR:*UTF8)
*
D CHAR10 S 10
D RTCHA1 S 10
D RTCHA2 S 10
D RTCHA3 S 10
C EVAL CHAR10='€'
C EVAL CHAR20=TXT(1)
C EVAL RTCHA1=%SUBST(CHAR10:1:1)
<<SNIP>>

The euro sign hex is E282AC (3 bytes).
If I try to substring CHAR10 I obtain this:
C EVAL RTCHA1=%SUBST(CHAR10:1:1)
RTCHA1 = 'S■■■■■■■■■' hex 'E2202020 20202020 2020'
<<SNIP>>

So it seems that %subst does not substring characters, but bytes.
I'm doing something wrong or this is working as expected?
How can I substring CHAR10?
Thanks for any advice.

I expect that the expression %SUBST(%UCS2(CHAR10):1:2) could be used to obtain the first double-byte character from the UTF8 character string; I presume that having been assigned to a UTF8 variable, the appropriate CCSID translation would transpire.

Or similarly, using the SQL SUBSTRING() scalar that operates on _characters_ instead of on _bytes_; the SQL SUBSTR() scalar operates on bytes, as described was the effect using the %SUBST() opcode:

Exec SQL
set :RTCHA1 = SUBSTRING(:CHAR10, 1, 1) ;


As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.