1

i need to find out a string from collection of strings using its sub string. This sub string must be in starting.

1

2 Answers 2

10
collection.FirstOrDefault(s => s.StartsWith(whatever))
Sign up to request clarification or add additional context in comments.

1 Comment

Or, if there could be more than one, use collection.Where(s => s.StartsWith(whatever))
2

you can do something like this,

List<string> collection = new List<string>();
        collection.Add("example sample");
        collection.Add("sample");
        collection.Add("example");

        var varSubstring = collection.Where(x => x.IndexOf("sample")==0).ToList();
        foreach (var vartemp in varSubstring)
        {
        }

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.