Hey Robert,
In Java, both Character and char are Unicode. So, you can unbox Character to char but you'll still have unicode.
Also, although it intuitively seems like converting unicode to ascii should be easy, I've spens a bunch of time with this and was never able to do it completely. Here is what I have been using:
From chatGPT:
import java.text.Normalizer; import java.util.regex.Pattern;
public class UnicodeToAsciiConverter {
public static String convertToAscii(String unicodeStr) { String normalized = Normalizer.normalize(unicodeStr, Normalizer.Form.NFD); Pattern pattern = Pattern.compile("[^\p{ASCII}]"); return pattern.matcher(normalized).replaceAll(""); }
public static void main(String[] args) { String unicodeString = "Héllo, Wörld! 👋"; // Example Unicode string String asciiString = convertToAscii(unicodeString); System.out.println("Original Unicode String: " + unicodeString); System.out.println("Converted ASCII String: " + asciiString); } }
--blake
On Wed, Jan 3, 2024 at 2:27 PM Robert Dodier robert.dodier@gmail.com wrote:
Hi, is there a way to unwrap a Java boxed value to get the Java primitive value inside it?
In particular I am interested in obtaining the char inside a Character, in order to supply the char to a method which requires a char.
Thanks for any info,
Robert