B4J Question Unicode sequence in module


Licensed User
Longtime User
I'm re-creating some java code in b4j and have this line of java:

String unicode = "\u20AC\u0020\u201A\u0192\u201E\u2026\u2020\u2021\u02C6\u2030\u0160";

So in my b4j Main module i have written:

Dim Unicode As String="\u20AC\u0020\u201A\u0192\u201E\u2026\u2020\u2021\u02C6\u2030\u0160"

The unicode sequence is passed to a class that is part of a PDF creation library.
The java example for this library renders as the unicode sequence in a PDF document:

€ ‚ƒ„...†‡ˆ‰Š

My b4j example renders the unicode sequence literally:


Looking at the compiled main.java source file for my b4j example the relevant line is:

_unicode = "\\u20AC\\u0020\\u201A\\u0192\\u201E\\u2026\\u2020\\u2021\\u02C6\\u2030\\u0160";

Each slash in my sequence has been escaped - is this preventing the sequence from being recognised as a unicode sequence?
Is there a supported method to pass a unicode sequence from a b4j module to a library method?




Well-Known Member
Licensed User
Longtime User
I use js to convert unicode as it handles unicode natively. I wrote a tiny lib, that just contains a scriptengine.
Sub readUnicode(st As String) As String
    Dim m As MyEval
    m.evalString("var x = '" & st & "';")
    Return m.engineGet("x")
End Sub
the java source for the lib is :
package myEval;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

import anywheresoftware.b4a.BA.Author;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
public class MyEval {
    ScriptEngineManager factory = new ScriptEngineManager();
    ScriptEngine engine;
    Object reply;

    public MyEval() {
        this.engine = factory.getEngineByName("JavaScript");
    public Object evalString(String s){
        try {
            reply =  this.engine.eval(s);
        } catch (ScriptException e) {
            reply = null;
        return reply;
    public void enginePut(String a,Object b){
        this.engine.put(a, b);
    public Object engineGet(String a){
        return this.engine.get(a);
Plus the library exposes js for use in B4J.
Upvote 0


Well-Known Member
Licensed User
Longtime User
Sorry Erel, I will post it in there with a documented B4J project to show how to use it for people not familiar with javascript engine.

Would jScriptEngine be ok for it's name ?
Upvote 0