About 34,800 results
Open links in new tab
  1. Convert character to ASCII numeric value in java - Stack Overflow

    May 9, 2013 · char character = 'a'; int ascii = (int) character; In your case, you need to get the specific Character from the String first and then cast it. char character = name.charAt(0); // This gives the character 'a' int ascii = (int) character; // ascii is now 97. Though cast is not required explicitly, but its improves readability.

  2. Converting ASCII code to char in Java - Stack Overflow

    Oct 22, 2012 · ASCII characters can have zero at the begining, because of that conversion from String to Integer have to be done correctly. Working solution is shown below. String s= "01001000"; int AsciiCode = Integer.valueOf(s, 2); char c= (char) AsciiCode; System.out.println(c);

  3. java - How to convert ASCII code (0-255) to its corresponding …

    Nov 2, 2016 · You're completely correct that something like Character.toString((char) i) is faster than String.valueOf(Character.toChars(i)). Running a quick benchmark of converting 1,000,000 random integers in the given range (100 times, to be safe) on my machine gives an average time of 153.07 nanoseconds vs. 862.39 nanoseconds.

  4. java - How to check if a String contains only ASCII ... - Stack Overflow

    Aug 27, 2010 · Here ASCII includes all ASCII characters including the non-printable characters lower than 0x20 (space) such as tabs, line-feed / return but also BEL with code 0x07 and DEL with code 0x7F. This code incorrectly uses characters rather than code points, even if code points are indicated in the comments of earlier versions.

  5. Java - Change int to ascii - Stack Overflow

    Mar 16, 2011 · So, any US-ASCII number (0-127) is also a Unicode code point (0-1,114,111). To change a code point number to a String object containing a single character, call Character#toString. String x = Character.toString( 97 ) ; a. See this code run live at IdeOne.com.

  6. How to convert a Java String to an ASCII byte array?

    Apr 16, 2011 · @RoyiNamir: This might be better posted as a new question, but the reason is that character is not encodable in US-ASCII and the getBytes(Charset) method is specified to replace characters that can not be encoded. With US-ASCII, this replacement char is the question mark, so your byte array contains one element with the ASCII value of '?' (63).

  7. java - What are all the escape characters? - Stack Overflow

    Sep 20, 2017 · These are escape characters which are used to manipulate string. \t Insert a tab in the text at this point. \b Insert a backspace in the text at this point. \n Insert a newline in the text at this point. \r Insert a carriage return in the text at this …

  8. Convert character to ASCII code in JavaScript - Stack Overflow

    Sep 18, 2008 · As others have pointed out, ASCII only covers 128 characters (including non-printing characters). Unicode includes ASCII as its first 128 characters for the purpose of backwards compatibility, but it also includes far more characters. To get only ASCII character codes as integers, you can do the following:

  9. Incrementing Char Type In Java - Stack Overflow

    Jun 15, 2013 · A char in Java is just an integer number, so it's ok to increment/decrement it. Each char number has a corresponding value, an interpretation of it as a character, by virtue of a conversion table: be it the ASCII encoding, or the UTF-8 encoding, etc. Come to think of it, every data in a computer - images, music, programs, etc. are just numbers.

  10. Java Regexp to Match ASCII Characters - Stack Overflow

    Feb 21, 2011 · I tried, single slash works as well. Normally you need double slash because it's an escape command. By the way, I had problems with an String because it has chars from the extended ASCII, but \\p{ASCII} is only the standard. For extended ASCII you can use ^[\\u0000-\\u00FE]*$ (FE instead of 7F) –