Here you can find the source of charToEscape(char ch)
Parameter | Description |
---|---|
ch | Character to be converted. |
public static String charToEscape(char ch)
//package com.java2s; /*/* ww w. jav a 2 s.c o m*/ * Copyright (C) 2014 Dell, Inc. * * 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 { /** * Return the Java Unicode escape sequence for the given character. For example, the * null character (0x00) is converted to the string "\u0000". This method is useful * for creating display-friendly strings that contain hidden non-printable characters. * * @param ch Character to be converted. * @return String containing the Java Unicode escape sequence for the given * character. */ public static String charToEscape(char ch) { String hexValue = Integer.toHexString(ch); if (hexValue.length() == 1) { return "\\u000" + hexValue; } if (hexValue.length() == 2) { return "\\u00" + hexValue; } if (hexValue.length() == 3) { return "\\u0" + hexValue; } return "\\u" + hexValue; } }