0

I have two variables but same value, one is a String that is retrieved from a database, and the other is generated in the program. For exemple :

 String encodedImage="FFD8FFFE002460000D11000000000000000000000000000000F0004001230032"
+"120B510451040000FFDB008400090607080705090807080A09090A0D160E0D0C"; 

//this is the variable generated in the program

String vartable="FFD8FFFE002460000D11000000000000000000000000000000F0004001230032\r\n120B510451040000FFDB008400090607080705090807080A09090A0D160E0D0C

// this is the string retrieved from database, it is a json then parsed to a string

The string is a representation of a picture so it is much longer but here is the first two lines. The problem is that if I compare the 2 string

if( encodedImage.equalsIgnoreCase(vartable)

I obtain that the 2 string does not match Any help ? I am doing a android application and I must have the same string to have the same picture

2 Answers 2

1

You have a \r\n sequence in one of the strings(vartable). Therefor the two strings are not equal - one of them has two characters more. You could have detected this easily by debugging - the length of the two strings is not the same and this is probably one of the first checks that equals and its variations perform.

Sign up to request clarification or add additional context in comments.

5 Comments

I guess this is not consider as a character when compiling, this is to return to a new line
Of course it is considered a character. Please try and debug your program and take a look at the lengths of the two strings that you try to compare. Two strings of different length will never be equal. Maybe you need to remove white spaces before comparing?
when I put the string in a textview I dont see the \r\n
Yes, You will not see the \r\n in text view. Remove them before comparing.
\n\r appears in the json format but when I pasrse the json to a string I dont see the \n\r
1

Try this,

vartable = vartable.replaceAll("\r\n", "");

and then compare the 2 strings,

if (encodedImage.equalsIgnoreCase(vartable))

2 Comments

\n\r appears in the json format but when I pasrse the json to a string I dont see the \n\r
Can you share your json, or the url?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.