why the two types are different between readfile and string in kotlin?

jakchang :

I want to read text file and use that strings. so I used raw folder and wrote one YouTube URL.

When I read the .txt file and try to transfer to next activity, that URL didn't work.

So, I compared the literal to text file string. but the types were different.

I don't understand this. How can I solve this problem?

musicfile.txt

lLZLWUz2veg

MainActivity

var music_url = readFile(musicfile).split("\n")
var url = music_url.get(item.id)
var isEquals = music_url.get(item.id).equals("lLZLWUz2veg")
Log.d("Tag","equals : "+isEquals)
Log.d("Tag","url : "+url)
Log.d("Tag","literal : lLZLWUz2veg")

Result

D/Tag: equals : false
D/Tag: url : lLZLWUz2veg
D/Tag: literal : lLZLWUz2veg
Blundell :

Since you don't declare the types, ensure you are using Structural Equality (‘==’)

https://medium.com/@agrawalsuneet/equality-in-kotlin-and-equals-d8373ef529f1

and

Check that your URL does not include the newline character on the beginning or end. You will not be able to tell with your current log statement.

i.e:

val music_url = readFile(musicfile).split("\n")
val url = music_url.get(0) // I assume its 0? makes the question clearer
val literal = "lLZLWUz2veg"
val isEquals = url == literal

Log.d("Tag", "equals : $isEquals")
Log.d("Tag", "url : [$url]") // Putting [] characters either sides will expose new lines
Log.d("Tag", "literal : [$literal]")

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=7357&siteId=1