BlackBoard » Design, Programmierung & Entwicklung » Programmieren » Java Umwandlungsproblem » Hallo Gast [Anmelden|Registrieren]
Letzter Beitrag | Erster ungelesener Beitrag Druckvorschau | An Freund senden | Thema zu Favoriten hinzufügen
Neues Thema erstellen Antwort erstellen
Zum Ende der Seite springen Umwandlungsproblem
Autor
Beitrag « Vorheriges Thema | Nächstes Thema »
kilone kilone ist männlich
Senior Member


images/avatars/avatar-131.gif

Dabei seit: 13.09.2001
Beiträge: 320

verrückt Umwandlungsproblem       Zum Anfang der Seite springen

Hi ich hab ein Problem mit der Umwandlung einzelner Zeichen.
Wenn ich z.B:
code:
1:
2:
3:
4:
5:
6:
String uni = "€";
byte [] byt = uni.getBytes();

System.out.println("String: "+uni+" ToByte[]: "+byt[0]+" ToChar:"+(char)byt[0]);


mache bekomme ich als Ausgabe:
code:
1:
String: € ToByte[]: -128 ToChar:?


Ich denke mal das das ein Problem mit dem ASCII ist weil € ein Unicode Zeichen ist. Aber wie kann ich das Java beibringe das er mir da wieder das richtige Zeichen ausgibt? Ich hoffe ihr könnt mir helfen weiß nämlich nicht mehr weiter unglücklich


mfg

Kilone

__________________
Klick mich fest
08.07.2007 14:12 kilone ist offline E-Mail an kilone senden Homepage von kilone Beiträge von kilone suchen
phoenix
Moderator


Dabei seit: 22.08.2003
Beiträge: 1.157

      Zum Anfang der Seite springen

Schau dir das mal genauer an.

code:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:

* Copyright (c) 1995-1998 Sun Microsystems, Inc. All Rights Reserved.

/*
 * Copyright (c) 1995-1998 Sun Microsystems, Inc. All Rights Reserved.
 *
 * Permission to use, copy, modify, and distribute this software
 * and its documentation for NON-COMMERCIAL purposes and without
 * fee is hereby granted provided that this copyright notice
 * appears in all copies. Please refer to the file "copyright.html"
 * for further important copyright and licensing information.
 *
 * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
 * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
 * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
 * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
 */

import java.io.*;
import java.util.*;

public class StringConverter {

   public static void printBytes(byte[] array, String name) {
      for (int k = 0; k < array.length; k++) {
         System.out.println(name + "[" + k + "] = " + "0x" +
            UnicodeFormatter.byteToHex(array[k]));
      }
   }

   public static void main(String[] args) {

      System.out.println(System.getProperty("file.encoding"));
      String original = new String("€");
   
      System.out.println("original = " + original);
      System.out.println();
   
      try {
          byte[] utf8Bytes = original.getBytes("UTF8");
          byte[] defaultBytes = original.getBytes();
 
          String roundTrip = new String(utf8Bytes, "UTF8");
          System.out.println("roundTrip = " + roundTrip);
 
          System.out.println();
          printBytes(utf8Bytes, "utf8Bytes");
          System.out.println();
          printBytes(defaultBytes, "defaultBytes");
      } catch (UnsupportedEncodingException e) {
          e.printStackTrace();
      }
      
   } // main

}



mfg
08.07.2007 15:19 phoenix ist offline Beiträge von phoenix suchen
Baumstruktur | Brettstruktur
Gehe zu:
Neues Thema erstellen Antwort erstellen
BlackBoard » Design, Programmierung & Entwicklung » Programmieren » Java Umwandlungsproblem

Forensoftware: Burning Board 2.3.6, entwickelt von WoltLab GmbH