vendredi 14 février 2020

if statement never returns true in scala when comparing strings

im reading text from a text file in scala. im having difficulties with if statements.

for (line <- Source.fromFile(filename).getLines) {
    if (line.length>7){println("b1  >" + line(7)+ "<    " + line(0).getType);
    if(line(7)=="#"){println("hashtag")}}}

below is 2 lines from my text file. the first line has 4 spaces followed by many hashtags. the second line is 4 spaces followed by 1 hashtag (the 4 spaces keep getting deleted by stack overflow)

##################################################################################################################################################
#

below is the output i recieve

//| b1  >#<    12
//| b1  > <    12

Question 1) why is getType returning 12... 12 is the strangest data type ive ever heard of. Question 2) (possibly answered by Q1) why does the if(line(7)=="#") statement never returns true?

Aucun commentaire:

Enregistrer un commentaire