Re: Get words. Suggestions to improve code.
- From: "Mike 'Spike' Lovell" <no.email.address.provided@xxxxxxxxxxxx>
- Date: Sat, 17 Oct 2009 11:08:23 -0500
"shapper" <mdmoura@xxxxxxxxx> wrote in message news:92694b5b-87e6-41c7-a546-6ebf6f51aaf2@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Oct 17, 2:54 am, "Mike 'Spike' Lovell"
<no.email.address.provi...@xxxxxxxxxxxx> wrote:
You say "improve" like there's a problem, is there a problem or some
scenario you have in mind here?
I am not sure because enumerating the delimiters feels strange.
I am trying the following:
public static IEnumerable<String> Words(this String value) {
MatchCollection collection = Regex.Matches(value, @"\b(?:\w|\')+
\b");
Match[] matches = new Match[collection.Count];
collection.CopyTo(matches, 0);
return matches.Select(m => m.Value).AsEnumerable();
} // Words
And then I apply it as follows:
keywords = String.Join(",", model.Title.Words().Where(w => w.Length >
3).Select(w => w.Capitalize()).Take(5).ToArray());
It seems better now ... not?
Wish I knew some RegEx!
Well, as the other poster pointed out (about the missing punctuation) a
RegEx might be the way to go. But I have no idea what that RegEx indicates.
Also, you need to account for what type of encoding the input is, just
ANSI/ASCII? Or Unicode? In the case of the later, perhaps some more
thought required.
~ Mike
.
- References:
- Get words. Suggestions to improve code.
- From: shapper
- Re: Get words. Suggestions to improve code.
- From: Mike 'Spike' Lovell
- Re: Get words. Suggestions to improve code.
- From: shapper
- Get words. Suggestions to improve code.
- Prev by Date: Re: Double Division
- Next by Date: How to use LINQ on DataTable-object?
- Previous by thread: Re: Get words. Suggestions to improve code.
- Next by thread: Los Angeles Locksmith | Residential Locksmith | Commercial Locksmith | Auto Locksmith | (877) 364-5264
- Index(es):
Relevant Pages
|