0

Could someone please give an example of how to use ling to query over a long string of text and find a substring within that string?

regards

3
  • Can you give an example of the string and the substring you want to search for. Doesn't String.Substring() fit your need ? Commented Jun 23, 2009 at 15:08
  • Can you give a sample string? It is better to use regex for text parsing. Commented Jun 23, 2009 at 15:08
  • Sort of duplicate: stackoverflow.com/questions/1028846 Commented Jun 23, 2009 at 15:19

3 Answers 3

17

I wouldn't use LINQ, I would use String.Substring, String.IndexOf, or a regular expression.

Can you post an example of the string you would like to search and an example of a substring you would like to find within that string?

Sign up to request clarification or add additional context in comments.

Comments

3
static void Main(string[] args)
{
    var found = "Where in the world is Carmen Sandiego".Split(' ').Where(part => part.StartsWith("i"));
    foreach (var part in found)
        Console.WriteLine(part);
}

Comments

2

Making a leap here, but if you want to find a word within a long string and pick it out based on some criteria using LINQ, you could do something like this...

private static string longString = "This is a really long string";
static void Main(string[] args)
{
    var query = from word in longString.Split(' ')
                where word.StartsWith("r")
                select word;
}

I'm saying nothing about whether LINQ is an appropriate technology here.

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.