Browsing 7239 questions and answers with Jon Skeet

How do I remove emoji characters from a string?

I've got a text input from a mobile device. It contains emoji. In C#, I have the text as Text 🍫🌐 text Simply put, I want the output text to be Text text I'm trying to...
Jon Skeet
people
quotationmark

Assuming you just want to remove all non-BMP characters, i.e. anything with a Unicode code point of U+10000 and higher, you can use a regex to remove any UTF-16 surrogate code units from the string. For example: using System; using... more 1/19/2015 1:36:07 PM

people

Java IO Error when writing but not when reading

So the problem is I try to read the configuration file that is packed inside the .jar which works fine but then when it comes to writing to the file the file can not be found yet...
Jon Skeet
people
quotationmark

You can't just write to a file within a jar file - it's not a file in the regular sense. While you could unpack the whole jar file, write the new content, then pack it up again, it would be better to redesign so that you don't need to... more 1/19/2015 11:23:27 AM

people

.NET: How to get time for keypress as precisely as possible?

I am trying to build an application that does not have to be super performant in general, except for the timestamp of a keyboard press (or external controller button press). I...
Jon Skeet
people
quotationmark

From comments: I am looking for the difference between the start of an event and the key press. It's important to understand that that's very different to trying to get the actual timestamp of a key press. This situation is exactly... more 1/19/2015 11:08:52 AM

people

How comparison Object and primitive, with operator == works in Java?

For example: Long objectLong = 555l; long primitiveLong = 555l; System.out.println(objectLong == primitiveLong); // result is true. Is there invocation objectLong.longValue()...
Jon Skeet
people
quotationmark

As ever, the Java Language Specification is the appropriate resource to consult From JLS 15.21.1 ("Numerical Equality Operators == and !="): If the operands of an equality operator are both of numeric type, or one is of numeric type... more 1/19/2015 10:20:52 AM

people

How to count the number of "correct" and "incorrect" responses

I'm new to coding and am creating a windows form application in C#. I was having difficulties figuring out how to track the number of correct and incorrect responses. When a...
Jon Skeet
people
quotationmark

The immediate problem is that the type of the Text property is string, not int - you have to set it to text, not a number. Fortunately, you can just call ToString on an int to get a string representation. However, I'd suggest there are... more 1/19/2015 6:55:45 AM

people

Really simple java syntax clarification

I've never learned Java, but I need to understand what the following piece of code means, the main question is the curly braces: /** * This Universe uses the full HashLife...
Jon Skeet
people
quotationmark

That's an instance initializer. It's a bit of code which is executed as part of constructing a new instance, before the constructor body is executed. It's odd to have it laid out in that way though, directly after a method. (It's... more 1/18/2015 6:22:07 PM

people

Updating Hebrew text in SQL Server database end up with "???"

I'm writing a C# program to enter data into SQL Server 2008 database. I use the following function to enter info into database public bool AddSupplier(string name, string...
Jon Skeet
people
quotationmark

Just use parameterized SQL for the update command as well as the insert command. You should be doing that anyway in order to prevent SQL Injection attacks - the fact that it plays better with non-ASCII characters is a bonus. (IIRC, you... more 1/18/2015 7:57:12 AM

people

In Java super.getClass() prints "Child" not "Parent" why is that?

In Java classes and objects, we use "this" keyword to reference to the current object within the class. In some sense, I believe "this" actually returns the object of...
Jon Skeet
people
quotationmark

A method call using super just ignores any overrides in the current class. For example: class Parent { @Override public String toString() { return "Parent"; } } class Child extends Parent { @Override public String... more 1/17/2015 5:56:31 PM

people

Java insert into array after converted to list

String[] arr = { "Java", "Champ", "." }; List<String> list = (List<String>) Arrays.asList(arr); // line 1 arr[2] = ".com"; // line 2 ...
Jon Skeet
people
quotationmark

Arrays.asList doesn't copy the array into a list - it creates a view onto the array. Any change you make via the list affects the array, and vice versa. That's why you can't add to (or remove from) the list returned by Arrays.asList -... more 1/17/2015 5:53:06 PM

people

Why json doesn´t work?

When I try to run my project my game crash with this error: Exception in thread "LWJGL Application" java.lang.NullPointerException at...
Jon Skeet
people
quotationmark

Looking at the source code, it looks like the problem is that you haven't set a writer. It's not clear what you expect writeValue to do when you haven't set a writer, but you either need to change which method you call (e.g. calling... more 1/17/2015 11:48:34 AM

people