2

Possible Duplicate:
How to split a string while preserving line endings?
How do I split a string by strings and include the delimiters using .NET?

I'm splitting text into sentences. mystring.Split('.','!', '?') returns the sentences without the ./!/? on them. I need to have it return a sentence with the split param on the end? How does that go? Thanks

public static string[] GetSentences(string text)
{
    return text.Split('.', '!', '?'); 
}

I can think of one way to do it, by combining two separate arrays, but I think it looks awful so I thought I'd ask you professionals for a "proper" way :D

Edit - never mind close its a duplicate. I found the other threads, sorry

Community
  • 1
  • 1
Epic Nobody
  • 189
  • 6
  • How about posting your solution? – p.campbell Nov 29 '11 at 22:17
  • 1
    Note that `.` doesn't always mean the end of a sentence. It can also occur in the middle of a sentence, for example after an abbreviation. You may want to consider using a natural language library if you want a more accurate result. – Mark Byers Nov 29 '11 at 22:20

1 Answers1

1

Right, string.Split() isn't the right tool here.

Either simply loop through it (string.IndexOf())

or use a RegEx: ([^\.!?]+[\.!?])*

I'm not 100% sure about the escaping.

H H
  • 263,252
  • 30
  • 330
  • 514