none
Split a string if it contains enter key c#

    Question

  • I have a text like this:

    VGI AUSSEN SCHRANKE IH
    VGI AUSSEN TUER IH
    VGI EG HE 001d

    and I want to Split it for 3 parts depends on "enter key"

    Wednesday, April 12, 2017 9:31 AM

All replies

  • For example :

    {
                    string sString = @"VGI AUSSEN SCHRANKE IH
    VGI AUSSEN TUER IH
    VGI EG HE 001d";
                    string[] sLines = sString.Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (string sLine in sLines)
                    {
                        Console.WriteLine(sLine);
                    }
    }

    • Proposed as answer by RohitArora Wednesday, April 12, 2017 10:09 AM
    Wednesday, April 12, 2017 9:52 AM
  • If the text is in textbox or file, then see also Lines properties and File.ReadAllLines.

    Wednesday, April 12, 2017 10:34 AM
  • it works, thank you :)
    Thursday, April 13, 2017 6:16 AM
  • Hi kauthar1992,

    Thank you for your update.

    If you solved  this issue successfully, please mark Viorel's reply as answer, it will benefit other community members who encountered similar issues.

    Have a good day:)

    Best Regards, 


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, April 14, 2017 8:02 AM
    Moderator
  • Thanks for Castorix31 and Viorel_'s help.

    Hi kauthar1992,

    I think use the  Split() method of a string would be a nice solution for this issue.

    Anyway, since it has been resolved, if possible, please mark it as the answer. So we could close this case for you:)

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, April 19, 2017 9:06 AM
    Moderator