0

I'm trying to determine a way to find all words in a database table called 'Word' that contain certain letters which is easy enough for single instances of letters, for example if I want to find all words that contain 'L' and 'I' I would use:

Words.Where(w => w.Word_value.IndexOf("I") > 0 && w.Word_value.IndexOf("L") > 0)

However, if I needed to find all words containing the letter 'I' and three instances of the letter 'L' (e.g. 'LILLY'), I am at a loss. Is there a way I can do a count of instances of a string within another?

Any help would be greatly appreciated.

1

2 Answers 2

2

Try this.

int count = Words.Length - Words.Replace("L", "").Length;
Sign up to request clarification or add additional context in comments.

1 Comment

I hope you checked why i stick to this method. stackoverflow.com/questions/541954/…
1

I would recommend using SQL Server's full text search capabilities.

Create a stored procedure that implements the functionality you require using full text search and then expose that using Linq to Sql or Linq to Entities.

Also see the CONTAINS predicate.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.