Does a Table change a String format? (String equality)

Hello,

I am writing a program that calls for information to be pulled from a spread sheet (.csv format) and put into “tile” objects that exist in the program. The quick version of my question is that when I load a String into the program from the .csv file there is some formatting issue where the program does not recognize it as the String listed in the spread sheet. Is there something that happens to the format of a String when it’s extracted from a spread sheet? Thank you for the help, more specifics below.

The spread sheet has 4 columns, each one for a corresponding attribute to the class Tile object:

“Tile Number” which stores int values (the number of each tile in the array of tiles)
“Roll Number” which stores int values
“Resource” which stores String values
“Robber” which stores String values

class Tile {
  int rollnum;
  String resource;
  color c;
}

The “Tile Number” and “Roll Number” information works as expected. The color attribute for each tile is set in the display() function based off of the resource string value. For example:

if (resource == "Sheep") {
      //light green
      c = color(0, 255, 0);
    }

When I load in the spread sheet, tile1.resource is set to the spreadsheet’s corresponding “Resource” row which in this instance stores the value “Sheep”. If I run

println(tile1.resource)

The command line prints “Sheep”.

However the color variable never gets set to the new color value. After doing a little digging I ran the following code as a check.

if (tile1.resource == "Sheep"){
    println("They are equal");
  }else{
    println("They are NOT equal");
  }

The command line prints “They are NOT equal”. So my question is, does something about the String change when it’s stored in a .csv file as opposed to say a .txt file?

As always, thank you for the help.

Yeah you can’t really check string with ==

Instead use if(s1.equals (“Sheep”))

1 Like

I knew as soon as I posted this the answer was something like this. I just couldn’t quite place it. Thank you as always for the help!

1 Like

Hello,

@dtools22 Many have come across this one including me!

Adding some references to the topic for more context and details.

On the Processing website:

Internet:

I like the details!

:)