A story that suffered from a space that does not disappear even if trimmed with Java The cause is BOM

After reading the csv file in Java, I was insanely troubled when processing strings.

--Background --Since there is a half-width space at the beginning of the character string, it could not be converted to int type. ――So, let's erase the half-width space! ――… Half-width space does not disappear! !! !!

Erase half-width space

As a simple method, perform String.trim (). (Unicode of the space at this time is ** \ u0020 **)

Even so, there is a space that does not disappear (unicode ** \ u00A0 **, etc.), but it was organized on the following site, so please refer to it. https://eng-entrance.com/java-string-trim

But this space didn't disappear by itself ...

Erase what looks like a half-width space

When it is output to the error log, the same display as "" (normal space) appears. If you copy and paste the space output at this time, a character code different from the normal space will be displayed. The unicode at that time \uFEFF ……… Um, who?

When I looked it up, this was the BOM unicode http://e-words.jp/w/BOM.html.

If you know this, you can replace it! ** Supported by String.replace ("\ uFEFF", "") **

** Space (like) has disappeared! Solution **

It seems that an error occurred because the read csv used UTF-8

Recommended Posts

A story that suffered from a space that does not disappear even if trimmed with Java The cause is BOM
A small story that is sometimes useful in Maven
Phenomenon that cannot log out even though it is described in devise
A story that suffered from a space that does not disappear even if trimmed with Java The cause is BOM
Setting method that the size does not change even if CSS is changed
The problem that the JDK set in JAVA_HOME does not appear even if java -version is performed at the command prompt
[Java] Dealing with the situation where the program that writes to the Output Stream of Process does not end even if waitFor
The story that Tomcat suffered from a timeout error in Eclipse
[Firebase] The problem that the currentUser of Firebase Auth does not become null even if the app is uninstalled.
How to interact with a server that does not crash the app
I tried to make a program that searches for the target class from the process that is overloaded with Java
The story that link_to is deep (cause unknown)
Even in Java, I want to output true with a == 1 && a == 2 && a == 3 (gray magic that is not so much as black magic)
MockMVC returns 200 even if I make a request to a path that does not exist
PATH does not pass ... The cause is the character code
The story that .java is also built in Unity 2018
At the time of dialogReturn event, I checked because it is not updated even if I specify a component with update
The story that the request parameter from the iPhone application could not be obtained successfully with the Servlet
It's not a big deal if you understand that I was addicted to receiving emails with Java Mail from Exchange Online
[Java] com.sun.glass.WindowEvent is imported and the window does not close
The story that a model is not a "correct representation of the real world" / the need for a bounded context
If the DB container does not start with Initializing database files
A story about hitting the League Of Legends API with JAVA
A story that struggled with the introduction of Web Apple Pay
[Gradle] Build a Java project with a configuration different from the convention
[Java] You might be happy if the return value of a method that returns null is Optional <>
When calling sshpass from Java with shell etc., it seems that it is necessary to have a path.
An active hash that can be treated as data even if it is not in the database
A story that even a man who does not understand C language could add new functions to Ruby 2.6
[Java] JUnit that NG if a method with a large number of lines is detected using black magic
[For beginners] When you want to say that the JVM (-D) option does not work with the java -jar command, or that the library is buggy.