3

I would like to use the following Java statement in GeneXus, but I don't know GeneXus' syntax for embedded Java code.

str = new String(str.getBytes("8859_1"), "UTF-8");

How can I do it?

Fede
  • 3,928
  • 1
  • 20
  • 28
Nyi Ma Lay Win Lae Aye
  • 6,250
  • 2
  • 13
  • 10
  • FYI: if you think you need to do this, you probably have done something wrong before reaching this point and may already have data-loss (depending on how exactly you reached this point). – Joachim Sauer Oct 20 '15 at 14:41

3 Answers3

9
&str = 'my text'

JAVA [!&str!] = new String([!&str!].getBytes("8859_1"), "UTF8");

Documentation Link

Gonzalo Gallotti
  • 2,413
  • 3
  • 23
  • 28
1

It needs Exception control as following.Without exception,java.io.UnsupportedEncodingException error will be appeared.

&str = 'text'

JAVA try { [!&str !] = new String([!&str !].getBytes("UTF-8")); } catch (java.io.UnsupportedEncodingException e) { }

Nyi Ma Lay Win Lae Aye
  • 6,250
  • 2
  • 13
  • 10
1

Para incluir codigo java, necesitas usar la palabra reservada "java" al principio de cada linea. Si en esa linea necesitas acceder a una variable/atributo de GeneXus, o que esa variable sea accesible por GeneXus, necesitas rodear el nombre de la variable con [!...!] Asi que tu codigo quedaria:

java try {
java [!&str!] = new String([!&str!].getBytes("8859_1"), "UTF-8");
java } catch (Exception ex) {
...
java }