Java Char Create toCharCode(String s)

Here you can find the source of toCharCode(String s)

Description

Returns a string representing the Unicode character codes of the characters comprising the string s.

License

Open Source License

Parameter

Parameter Description
s the string whose character codes are to be represented

Return

a string representing the Unicode character codes of the characters comprising the string s

Declaration

public static String toCharCode(String s) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*  w  w  w  .  j  a  va2 s  .  c  o m*/
     * Returns a string representing the Unicode character codes of the characters comprising the string <code>s</code>.
     * 
     * <p>
     * Example:
     * </p>
     * 
     * <pre>
     * <code>
     * toCharCode("a") returns "97"
     * toCharCode("b") returns "98"
     * toCharCode("c") returns "99"
     * toCharCode("What's for lunch?") returns "87104971163911532102111114321081171109910463"
     * </code>
     * </p>
     * 
     * @param  s the string whose character codes are to be represented
     * @return a string representing the Unicode character codes of the
     *         characters comprising the string
     * <code>s</code>
     */
    public static String toCharCode(String s) {
        StringBuilder sb = new StringBuilder(s.length());

        for (int i = 0; i < s.length(); i++) {
            sb.append(s.codePointAt(i));
        }

        return sb.toString();
    }
}

Related

  1. toCharacter(Object obj)
  2. toCharacter(Object object)
  3. toCharacter(Object value)
  4. toCharacter(String input, char defaultValue)
  5. toCharacter(String str, String charset)
  6. toCharListNumber(int value, String list)
  7. toChars(byte b, char[] result, int position)
  8. toChars(final int cp, final char[] buffer, final int offset)
  9. toChars(int codePoint, char[] dst, int dstIndex)