Java: How to remove  character appearing before £

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Java: How to remove  character appearing before £



Whenever I print or write the £ symbol , or even do anything with it, it is always displayed as £ with no reason for the  to be there. I have tried writing the character in unicode but it still resulted in this weird combination. Is there any way to remove this or stop it happening?


public class GenericClass

public static void main(String args)

System.out.println("£");




This is all that is printed:



enter image description here





Where are you printing it? It could be the screen/tool etc can't handle unicode properly.
– Bohemian
Aug 9 at 18:41





Just to the command line, that isn't the issue because it won't work when I just System.out.println() it.
– Thomas Rowe
Aug 9 at 18:43





public class GenericClass public static void main(String args) System.out.println("£".substring(1)); What does this produce for you?
– Dr3amer17
Aug 9 at 18:49



public class GenericClass public static void main(String args) System.out.println("£".substring(1));





That works well, ill research substring and see how i can apply that to where I need it. Thanks
– Thomas Rowe
Aug 9 at 18:56





@Dr3amer17 this is one of those cases where I wish StackOverflow allowed downvoting of comments. What you propose is just plain wrong. The fact that it works at all means the £ is not encoded as expected when compiled. And your proposal fails miserably for Unicode characters that are encoded in UTF-8 in such a way that the value of the 2nd byte does not match the value of the codepoint that is being encoded. The real solution is to fix the encoding, not work around it.
– Remy Lebeau
Aug 12 at 23:54


£




1 Answer
1



Your source file is probably UTF-8 and as such, treats £ as two 8-bit characters : £



For portability, you have to use escaped unicode sequences in your string literals like this.


public class GenericClass

public static void main(String args)

System.out.println("u00A3");







By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard