Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
sonnykr
Visitor

Sanitize special characters

Hi All,

How can I santize special characters using brighscript? I tried something like
print Asc("ä")

and it printed "0" instead of the actual ASCII value, which is "132"

The 2D api is skipping the special character, and leaving a space instead of rendering it. However, imagecanvas renders the special character just fine.

So 2 questions:
1. How to sanitize special character?
2. How to make 2D render special character?

Thanks!
0 Kudos
12 REPLIES 12
RokuKC
Roku Employee
Roku Employee

Re: Sanitize special characters

Make sure your .brs source code file is UTF-8 encoded if you are embedding non-7-bit ASCII characters, e.g. in string constants.

Otherwise, characters should generally be specified as Unicode code points.

132 (&h84) does not appear to be a printable Unicode codepoint. If you want 'ä' that would be 228 (&hE4).

If you are getting different results depending on the drawing method it sounds like there are other issues.
0 Kudos
sonnykr
Visitor

Re: Sanitize special characters

Make sure your .brs source code file is UTF-8 encoded if you are embedding non-7-bit ASCII characters, e.g. in string constants.


I tried Asc("ä") directly on Roku debugger console, and it returns 0 instead of the ASCII value.
0 Kudos
renojim
Community Streaming Expert

Re: Sanitize special characters

I don't think you can do it from the debugger. If you put the statement in a UTF-8 encoded source file as KC suggested it will print "228".

-JT
Roku Community Streaming Expert

Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.

I am not a Roku employee.
0 Kudos
RokuKC
Roku Employee
Roku Employee

Re: Sanitize special characters

"sonnykr" wrote:
Make sure your .brs source code file is UTF-8 encoded if you are embedding non-7-bit ASCII characters, e.g. in string constants.


I tried Asc("ä") directly on Roku debugger console, and it returns 0 instead of the ASCII value.


The console only supports 7-bit ASCII.
0 Kudos
sonnykr
Visitor

Re: Sanitize special characters

oh! I see.. thank you RokuKc and renojim! That solves my first issue.

Still unsure why roScreen does not render special chars
0 Kudos
EnTerr
Roku Guru

Re: Sanitize special characters

Telnet console is a crank indeed, re i18n. worth(example) = lots * words, so:
BrightScript Debugger> s = chr(228): ? s, len(s), asc(s)
? 1 228
0 Kudos
RokuKC
Roku Employee
Roku Employee

Re: Sanitize special characters

"sonnykr" wrote:
oh! I see.. thank you RokuKc and renojim! That solves my first issue.

Still unsure why roScreen does not render special chars


What font are you using?
0 Kudos
sonnykr
Visitor

Re: Sanitize special characters

I am using a custom font from my client. Wondering whether its a font issue! but how come it works fine on imageCanvas? It render the special char very well on canvas. I'm kinda confused.
0 Kudos
gabek
Visitor

Re: Sanitize special characters

If there are special tricks and or specific fonts to getting this working on an roScreen I'd love to learn more! I've tried many different fonts thinking that could be it, but have never been successful getting it to work. In my case I'm getting stuff out of ParseJSON. I've eventually just resorted to normalizing these characters on the backend as best as I can.

"RokuKC" wrote:
"sonnykr" wrote:
oh! I see.. thank you RokuKc and renojim! That solves my first issue.

Still unsure why roScreen does not render special chars


What font are you using?
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.