Re: Get words. Suggestions to improve code.

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




"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

.



Relevant Pages

  • Re: String.replaceFirst doesnt work
    ... Keep in mind, the first parameter is a regex, not a simple string, but ... Second keep in mind that replaceFirst does NOT modify the current ...
    (comp.lang.java.help)
  • Re: Null terminated strings: bad or good?
    ... single memory block, then each line is not individually allocated anyway. ... string of length N without storing that value with every string of length ... example scenario since that is what I had in mind. ...
    (comp.lang.c)
  • Re: Need Regex for phone number
    ... Quoth lotug: ... or did you have something else in mind? ... I was looking for regex that would identify the phone number in a ... txt string regardless of how it was formatted. ...
    (comp.lang.perl.misc)
  • Re: Fastest way to search a string for the occurance of a word??
    ... but the OP's question was what's the "Fastest way to search a string ... in all the tests I did here, the Regex was by far superior. ... However, of course, if you've got new regular expressions all ... Sure - but just that extra Match object could be relevant if the search ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: regular expression help
    ... Basically because if you remove everything that is optional in the regex below you end up with an empty regex: ... So the regex engine will try to match on every character in the string: ... , comma doesn't match, but the nothingness in front of it does. ... A quote followed by any sequence of characters that is not a quote, ...
    (microsoft.public.dotnet.framework)