-3

Let's say I have the following string: "This is a test. Haha.". I want to split it so that it becomes these there lines:

Hey. 
This is a test. 
Haha.

(Note that the space after the dot is preserved).

I tried to split the string using the Split method, and split by the dot, but it returns 3 new strings with the space before the string, and it removes the dots. I want to keep the space after the dot and keep the space.

How can I achieve this?

EDIT: I found a workaround, but I'm sure there's a simpler way:

 string a = "Hey. This is a test. Haha.";
        string[] splitted = a.Split('.');

        foreach(string b in splitted)
        {
            if (b.Length < 3)
            {
                continue;
            }

            string f = b.Remove(0, 1);

            Console.WriteLine(f + ". ");
        }
Evan Carslake
  • 2,267
  • 15
  • 38
  • 56
Gilbert Williams
  • 970
  • 2
  • 10
  • 24

1 Answers1

0

I can't test this but due to the post of Darin Dimitrov :

string input = "Hey. This is a test. Haha.";
string result = input.Replace(". ", ".\n");
Community
  • 1
  • 1
Leogout
  • 1,187
  • 1
  • 13
  • 32
  • This post does not answer the question as asked despite being accepted as answer. Please either suggest edit to question to align with the answer, or update your post to clarify what interpretation of the question it answers. – Alexei Levenkov Aug 02 '15 at 07:16
  • I'm still learning English, sorry if I miss something in the question, but I can't see what it is. Can you be more precise? – Leogout Aug 02 '15 at 07:21