Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Filter not working on substring

 
Mike London
Ranch Hand
Posts: 1290
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have a simple filter expression, but the substring is not matching anything.

I have a random generated name: "Mauro Rinderle" in a file called names.csv.

The following code doesn't match this name




If I do an indexOf(), then it works.

There are no quotes around the names in the file.

I've tried various combinations of start and end for the substring but nothing matches.

Any suggestions?

Thanks,

- mike
 
Paweł Baczyński
Saloon Keeper
Posts: 1958
38
Firefox Browser IntelliJ IDE Java Linux Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't use == to compare Strings. Use equals() instead.
AvoidTheEqualityOperator ← read this

Also, you could use startsWith() for your check.
 
Mike London
Ranch Hand
Posts: 1290
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paweł Baczyński wrote:Don't use == to compare Strings. Use equals() instead.
AvoidTheEqualityOperator ← read this

Also, you could use startsWith() for your check.


Can't believe I made that mistake. I say the same thing to developers all the time.

I'll chalk up my oversight to being "new with Lambdas" and such. ;)

Thanks very much for your reply!!!

- mike

P.S. I was also AMAZED (!!!) that Java processed the loop above, against 500,000 names in less than 1 second!
 
Campbell Ritchie
Marshal
Posts: 52630
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a beginsWith or startsWith method (or similar) in the String class which is probably better than substring in this context.
 
Mike London
Ranch Hand
Posts: 1290
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:There is a beginsWith or startsWith method (or similar) in the String class which is probably better than substring in this context.


Good suggestion, thanks. This was just a test to see how to read each line of a file using J8.

As I mentioned above, I was blown away by the sub-second result.

A table scan (without SQL) in a popular database package took 2.5 hours to visit each row...

Thanks again!

-mike
 
Campbell Ritchie
Marshal
Posts: 52630
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try it with a proper SQL database too; they are designed to read millions of lines a second like that.
 
Mike London
Ranch Hand
Posts: 1290
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Try it with a proper SQL database too; they are designed to read millions of lines a second like that.


Yup did that today....I imported the 500,000 test names into a MySQL database and created a RegEx query. It ran in about 1 to 2 seconds.

Thanks again!

- mike
 
Campbell Ritchie
Marshal
Posts: 52630
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!