chilly
chilly

Reputation: 304

Java single char String represented by multiple bytes

I have encountered a problem with String comparison. (yes I'm using .equals) I found that by converting my seemingly identical strings to charArray one has an additional index containing nothing.

Now I took my string apart using substring and getBytes()

string.substring(0,1).getBytes()

which prints [-17, -69, -65] all other substrings from this string for example:

string.substring(1,2).getBytes()

print a single array [100]

Upvotes: 0

Views: 79

Answers (1)

chilly
chilly

Reputation: 304

While writing this question I found the answer and decided to share in case someone encounters a similar problem. My problem could be solved by changing the files encoding.

The file was encoded in UTF-8 (according to notepad++) and I saved it as UTF-8 without BOM which removed the special char read from the file.

Upvotes: 1

Related Questions