Java UTF8 Encode toUTF8(String isoString)

Here you can find the source of toUTF8(String isoString)

Description

Convert ISO8859-1 format string (which is the default sent by IE to the UTF-8 format that the database is in.

License

Apache License

Declaration

public static String toUTF8(String isoString) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.UnsupportedEncodingException;

public class Main {
    /**//w w w . j  a  va  2s . c om
     * Convert ISO8859-1 format string (which is the default sent by IE
     * to the UTF-8 format that the database is in.
     */
    public static String toUTF8(String isoString) {
        String utf8String = null;
        if (null != isoString && !isoString.equals("")) {
            try {
                byte[] stringBytesISO = isoString.getBytes("ISO-8859-1");
                utf8String = new String(stringBytesISO, "UTF-8");
            } catch (UnsupportedEncodingException e) {
                System.out.println("UnsupportedEncodingException is: " + e.getMessage());
                utf8String = isoString;
            }
        } else {
            utf8String = isoString;
        }
        return utf8String;
    }
}

Related

  1. getUTF8Decoder(boolean ignoreEncodingErrors)
  2. getUTF8StringLength(String string)
  3. isUTF8(String encoding)
  4. toUTF8(byte[] bytes)
  5. toUTF8(String content)
  6. toUTF8(String s)
  7. toUTF8(String sourceStr)
  8. toUTF8(String str)
  9. toUTF8(String str)