I have a text file from which I am reading lines and processing each line one by one.
I came across this line:
(T)he film is never sure to make a clear point – even if it seeks to rely on an ambiguous presentation.
Between point
and even
I have three characters ,
-
and .
I tried printing out the characters as integers.
In Java:
String input = "(T)he film is never sure to make a clear point – even if it seeks to rely on an ambiguous presentation.";
int[] ords = new int[input.length()];
for (int i = 0; i < ords.length; i++)
ords[i] = (int) input.charAt(i);
which gives:
[40, 84, 41, 104, 101, 32, 102, 105, 108, 109, 32, 105, 115, 32, 110, 101, 118, 101, 114, 32, 115, 117, 114, 101, 32, 116, 111, 32, 109, 97, 107, 101, 32, 97, 32, 99, 108, 101, 97, 114, 32, 112, 111, 105, 110, 116, 32, 8211, 32, 101, 118, 101, 110, 32, 105, 102, 32, 105, 116, 32, 115, 101, 101, 107, 115, 32, 116, 111, 32, 114, 101, 108, 121, 32, 111, 110, 32, 97, 110, 32, 97, 109, 98, 105, 103, 117, 111, 117, 115, 32, 112, 114, 101, 115, 101, 110, 116, 97, 116, 105, 111, 110, 46]
In Python:
def get_ords(string):
return map(lambda x: ord(x), string)
which gives:
[40, 84, 41, 104, 101, 32, 102, 105, 108, 109, 32, 105, 115, 32, 110, 101, 118, 101, 114, 32, 115, 117, 114, 101, 32, 116, 111, 32, 109, 97, 107, 101, 32, 97, 32, 99, 108, 101, 97, 114, 32, 112, 111, 105, 110, 116, 32, 226, 128, 147, 32, 101, 118, 101, 110, 32, 105, 102, 32, 105, 116, 32, 115, 101, 101, 107, 115, 32, 116, 111, 32, 114, 101, 108, 121, 32, 111, 110, 32, 97, 110, 32, 97, 109, 98, 105, 103, 117, 111, 117, 115, 32, 112, 114, 101, 115, 101, 110, 116, 97, 116, 105, 111, 110, 46]
In java's result, the three characters ,
-
and are represented by
8211
and in python it is represented as 226, 128, 147
i.e. '\xe2', '\x80', '\x93'
. This discrepancy is resulting in different results when I process it in java and python.
I also noticed that if I remove ,
-
and from the string, the results are same for both.
Is it possible to solve this issue without having to remove the special characters.