March 16, 2008 03:12 by
admin
Mike Hadlow shows us a couple of examples of things that you can do to strings with LINQ:
string text = "The quick brown fox jumped over the lazy dog.";
// substring
text.Skip(4).Take(5).Write(); // "quick"
// remove characters
text.Where(c => char.IsLetter(c)).Write(); // "Thequickbrownfoxjumpedoverthelazydog."
string map = "abcdefg";
// strip out only the characters in map
text.Join(map, c1 => c1, c2 => c2, (c1, c2) => c1).Write(); // "ecbfedeeadg"
// does text contain q?
text.Contains('q').Write(); // true
The examples come from LINQ in Action.
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5