Java UTF8 Encode getUTF8StringLength(String string)

Here you can find the source of getUTF8StringLength(String string)

Description

Get length of UTF8 String Length

License

Apache License

Parameter

Parameter Description
string a parameter

Return

int of UTF-8 String Length.

Declaration

public static int getUTF8StringLength(String string) 

Method Source Code


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

import java.io.*;

public class Main {
    /**//from   www .ja va  2s .  c  o m
     * Get length of UTF8 String Length
     *
     * @param string
     * @return int of UTF-8 String Length.
     */
    public static int getUTF8StringLength(String string) {
        if (string == null) {
            return 0;
        }
        try {
            return string.getBytes("UTF-8").length;
        } catch (UnsupportedEncodingException uee) {
            // Ignore...
        }
        return 0;
    }
}

Related

  1. encodeUtf8(String url)
  2. getBufferedWriter(final File outFile, final String outEncoding)
  3. getUTF8Bytes(String string)
  4. getUTF8Bytes(String string)
  5. getUTF8Decoder(boolean ignoreEncodingErrors)
  6. isUTF8(String encoding)
  7. toUTF8(byte[] bytes)
  8. toUTF8(String content)
  9. toUTF8(String isoString)