Skip to content

Java. Extracting character from array that isn’t ASCII

I’m trying to extract a certain character from a buffer that isn’t ASCII. I’m reading in a file that contains movie names that have some non ASCII character sprinkled in it like so.

JavaScript

I was able to pick off the lines that contained the non ASCII characters, but I’m trying to figure out how to get that particular character from the lines that have said non ASCII character and replace it with an ACSII character from the map I’ve made.

JavaScript

I tried using something along the lines of:

JavaScript

But I’m not sure.

Advertisement

Answer

You can just use replaceAll. Put this in the while loop, so that it works on each line you read from the file. With this change, you won’t need the split and if (... matches) anymore.

JavaScript

If you want to keep a map, just iterate over its keys and replace with the values you want to map to:

JavaScript

Later, in your loop reading the contents, you replace all the characters:

JavaScript

Here is a complete example:

JavaScript

This prints:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful