1. Frank Zettanucci
  2. PowerBuilder
  3. Tuesday, 2 May 2023 14:19 PM UTC

Is anyone aware of a reliable PowerBuilder Powerscript way to identify if a string contains UTF-8 characters or not ?

 

Francisco Martinez @Appeon Accepted Answer Pending Moderation
  1. Tuesday, 2 May 2023 14:50 PM UTC
  2. PowerBuilder
  3. # 1

Hi Frank,

A string itself is nothing more than a sequence of bytes (in theory). These bytes have no particular meaning until you decide to interpret them under a particular schema (ASCII, UTF8, UTF16, etc). As such, based on my (very) limited understanding, a sequence of bytes can very well be a valid ASCII or UTF8 string depending on which schema you choose to interpret the byte sequence with. Whether or not this string will make sense, is another very different issue.

I would love to be proven wrong, however.

Regards,
Francisco

Comment
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Tuesday, 2 May 2023 20:19 PM UTC
  2. PowerBuilder
  3. # 2

Hi Frank;

  I have not tried this approach personally but, this might work (in theory) ...

String ls_data, ls_data_ansi

ls_data = "<Your Data>"
ls_data_ansi = String ( Blob (ls_data, EncodingANSI! ))
IF ls_data = ls_data_ansi  THEN
   MessageBox ("ANSI", "Data Found!")
ELSE
   MessageBox ("Unicode", "Data Found!")
END IF

HTH

Regards ... Chris

Comment
  1. Benjamin Gaesslein
  2. Wednesday, 3 May 2023 06:54 AM UTC
This will not compile, String( x, Encoding...! ) is for blobs, not strings. You must first convert ls_data to a blob like so:

ls_data_ansi = String ( Blob(ls_data, EncodingUTF8!), EncodingANSI! )



If the resulting string matches the original it is indeed safe to assume that it contains only ASCII characters.
  1. Helpful
There are no comments made yet.
William Hong Accepted Answer Pending Moderation
  1. Thursday, 4 May 2023 06:25 AM UTC
  2. PowerBuilder
  3. # 3

A string is always composed of Unicode characters encoded in UTF-16

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.