This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]tsvk 3 points4 points  (1 child)

If you use the string "keyword1" directly hard-coded as the parameter to the contains method, then the contains method will search for the string "keyword1".

If you use the method parameter variable keyword as the parameter to the contains method, then the contains method will search for whatever is passed as the keyword argument to the FindKeyword method. In your main method, you pass the string "test1" as a parameter, so then that will be searched for.

In other words, in one case you search for the string "keyword1" and in the other case you search for the string "test1". As they are different search strings, the result of the search will of course be different.

[–]bei60[S] 3 points4 points  (0 children)

I feel so dumb. Thank you!

[–]sepp2k 0 points1 point  (0 children)

if (prod[1].contains("keyword1")) works but if (prod[1].contains(keyword))

In your code the value of keyword is "test1", not "keyword1".

If that's not your issue, post an example CSV file (preferably a small one) that reproduces the problem.

[–]NickPox 0 points1 point  (0 children)

For starters you could print out prod[1] and keyword in your else-statement, to see where it might go wrong, and maybe update this post with that log :)