Splitting strings by line
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Splitting strings by line

  1. #1
    Join Date
    Dec 2011
    Posts
    1

    Splitting strings by line

    How can I split a string by lines... For example

    Line1
    Line2
    Line3



    I want to split it into a list

    so lines[1] = "line1"


    see? So how could I do this?

  2. #2
    Join Date
    Feb 2011
    Location
    United States
    Posts
    1,005

    Re: Splitting strings by line

    Code:
    string longString = //Whatever;
    string[] lines = allStringsTogether.Split("\r\n", StringSplitOptions.None);
    Or for maximum portability

    Code:
    string longString = //Whatever;
    string[] lines = allStringsTogether.Replace("\r\n","\n").Split('\n');
    N.B. that this scheme will give you a zero-indexed array:

    lines[0] = "line1"
    Best Regards,

    BioPhysEngr
    http://blog.biophysengr.net
    --
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center