Here you can find the source of toUnicode(final String toUnicode, final boolean toLowerCase)
Parameter | Description |
---|---|
toUnicode | The String to convert. |
toLowerCase | If true the letters from the unicode characters are lower case. |
public static String toUnicode(final String toUnicode, final boolean toLowerCase)
//package com.java2s; /**/*from w ww . j av a 2 s . c o m*/ * Copyright (C) 2007 Asterios Raptis * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { /** * Converts all characters from the given String to unicodes characters encoded like \uxxxx. * * @param toUnicode * The String to convert. * @param toLowerCase * If true the letters from the unicode characters are lower case. * @return The converted String. */ public static String toUnicode(final String toUnicode, final boolean toLowerCase) { final StringBuilder sb = new StringBuilder(); for (int i = 0; i < toUnicode.length(); i++) { final String hex = Integer.toHexString(toUnicode.codePointAt(i)); if (toLowerCase) { hex.toLowerCase(); } else { hex.toUpperCase(); } final String hexWithZeros = "0000" + hex; final String hexCodeWithLeadingZeros = hexWithZeros.substring(hexWithZeros.length() - 4); sb.append("\\u" + hexCodeWithLeadingZeros); } return sb.toString(); } }