4110

ASCII codes => string of characters

Question:

I have the next string of the ASCII codes:

[-76,-96,-80,106,-58,106,-1,34,7,123,-84,101,51]

What is the best way to convert it in the string of the characters of these codes values? Are there any pitfalls here?

Answer1:

You need to turn it into a corresponding byte array and then instantiate new String(byteArray).

String [] strings = input.substring(1, input.length()-1).split(","); byte[] bytes = new byte[strings.length]; int i = 0; for (String s : strings) bytes[i++] = Byte.parseByte(s); System.out.println(new String(bytes, "UTF-8"));

In place of "UTF-8" use your proper character encoding. It could be CP-1250, ISO-8859-1, or similar.

Recommend

  • How can i convert WriteableBitmap to jpg or some other common format?
  • SWIG get returntype from String as String array in java
  • Object de-serializing from base64 in C#
  • (Python 3) How to pass binary file as text without saving first
  • Convert array of strings to array of objects
  • Does Perl currently (5.8 and 5.10) make any promises about the order alternations will be used?
  • JPS useBean with HashMap
  • Cannot instantiate the type Image java?
  • pyspark substring and aggregation
  • Android Oreo JobIntentService Keep running in background for Android 7 &below and crashing often
  • Multilingual set up of codeigniter
  • Is there an HTML code that can make my background picture transparent and my text non-transparent?
  • How to initialize context? [closed]
  • remove unicode characters but keep all special and English characters with preg_replace
  • Replace last two characters in column
  • Adding a model to a Marionette CollectionView's collection doesn't trigger onItemAdd callb
  • several dataProvider per one Test in TestNG
  • Getting NullPointer exception with File.listfiles()
  • How to specify input and output paths from cmd.exe for a PowerShell script?
  • Convert SQLite database to XML
  • Convert Type Decimal to Hex (string) in .NET 3.5
  • WPF Visiblity Binding to Boolean Expression with multiple Variables
  • Conversion from string “a” to type 'Boolean' is not valid
  • What does 'Language neutral' mean with regard to MAKELANGID?
  • copying resource to sdcard gives a damaged file in android
  • Java Scanner input dilemma. Automatically inputs without allowing user to type
  • When should I choose bucket sort over other sorting algorithms?
  • what is the difference between the asp.net mvc application and asp.net web application
  • How do you troubleshoot character encoding problems?
  • Rearranging Cells in UITableView Bug & Saving Changes
  • AT Commands to Send SMS not working in Windows 8.1
  • Arrays break string types in Julia
  • Matrix multiplication with MKL
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • Benchmarking RAM performance - UWP and C#
  • Angular 2 constructor injection vs direct access
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • apache spark aggregate function using min value
  • Sorting a 2D array using the second column C++
  • Binding checkboxes to object values in AngularJs