Split function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?Ym9iYnk=?=

    #1

    Split function

    I have the following code. bit it gives me error that The best overload
    method for string.Split(pa rams char[]) has some invalid arguments. I am
    using stringbuilder which doesn't have split method so how can I do that.


    public static string[] ReadFileLines(s tring path)
    {
    int read = 0;
    StringBuilder builder = new StringBuilder() ;
    byte[] buffer = new byte[1024];

    using (FileStream readStream = File.Open(path, FileMode.Open,
    FileAccess.Read , FileShare.Read) )
    {
    while ((read = readStream.Read (buffer, 0, buffer.Length)) 0)
    builder.Append( Encoding.UTF8.G etString(buffer , 0, read));
    }


    return String.Split(bu ilder.ToString( ), "\r\n");

    }
  • Alberto Poblacion

    #2
    Re: Split function

    "bobby" <bobby@discussi ons.microsoft.c omwrote in message
    news:AD2BE310-43A2-4D0B-A44C-CA195B730514@mi crosoft.com...
    >I have the following code. bit it gives me error that The best overload
    method for string.Split(pa rams char[]) has some invalid arguments.
    [...]
    return String.Split(bu ilder.ToString( ), "\r\n");
    Do the Split on the result of converting the StringBuilder to String, and
    then pass several chars to satisfy the "params char[]" argument:

    return builder.ToStrin g().Split('\r', '\n');

    Comment

    • Alberto Poblacion

      #3
      Re: Split function

      In a previous message I wrote:
      return builder.ToStrin g().Split('\r', '\n');
      Now that I think about it, this is probably not what you intended in the
      first place, since this will break the string on every \n and every \r, and
      I suspect that you want to split on the "\r\n" sequence. This can be done
      with a new overload of Split available in the Framework 2:

      Split("\r\n", StringSplitOpti ons.None);


      Comment

      • =?UTF-8?B?QXJuZSBWYWpow7hq?=

        #4
        Re: Split function

        bobby wrote:
        I have the following code. bit it gives me error that The best overload
        method for string.Split(pa rams char[]) has some invalid arguments.
        return String.Split(bu ilder.ToString( ), "\r\n");
        return builder.ToStrin g().Split("\r\n ".ToCharArray() );

        maybe.

        Arne

        Comment

        Working...