Here you can find the source of toUnicode(String string)
Parameter | Description |
---|---|
string | The string to be converted. |
public static String toUnicode(String string)
//package com.java2s; /*//from w w w . j ava 2s . c o m * net/balusc/util/StringUtil.java * * Copyright (C) 2007 BalusC * * This program is free software: you can redistribute it and/or modify it under the terms of the * GNU Lesser General Public License as published by the Free Software Foundation, either version 3 * of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this library. * If not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * Convert the given string to a string with unicode escape sequence for every character. * @param string The string to be converted. * @return The string with unicode escape sequence for every character. */ public static String toUnicode(String string) { StringBuilder builder = new StringBuilder(); for (char c : string.toCharArray()) { builder.append(String.format("\\u%04x", (int) c)); } return builder.toString(); } }