However, remember that "co" can be null and "c" can't. So, you may have to do something like:
if (co == null) c = myDefault; else c = co;
On Wed, Jan 3, 2024 at 3:57 PM Blake McBride blake@mcbride.name wrote:
Java, auto-unboxes. So, you can do the following:
Character co = 'A'; char c = co;
On Wed, Jan 3, 2024 at 3:51 PM Blake McBride blake@mcbride.name wrote:
Sorry for the confusing message, although it is correct. When I said I spent a bunch of time on it with an incomplete solutions, I was talking about JavaScript.
So, except for the paragraph that starts with "Also, ...", the rest is correct.
--blake
On Wed, Jan 3, 2024 at 3:46 PM Blake McBride blake@mcbride.name wrote:
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