You must Sign In to post a response.
  • Category: ASP.NET

    Split String with Space(" ").But Avoid if in Quotation

    Hello EveryOne,

    I want to split string with space(" ") like this. but want to avoid if space in Quotation.

    EG: "0002150118463" 5.55 2.02 "FABIO CAPPELLO" "FABIO CAPPELLO" "" "Graffi sparsi dovuti apa" "0" "Sinistro aperto cond enun"

    It should split with Space and total Count of Words will be 9.

    Note: String is in CSV File.

    Let me know if u have any query

    Thanks in Advance
  • #764558
    Hi chirag,
    You can use regex for this purpose:

    using System.Text.RegularExpressions;

    string szString = "\"0002150118463\" 5.55 2.02 \"FABIO CAPPELLO\" \"FABIO CAPPELLO\" \"\" \"Graffi sparsi dovuti apa\" \"0\" \"Sinistro aperto cond enun\"";
    Regex regex123 = new Regex(@"""[\w\s]*""|\w+");
    var vResult = regex123.Matches(szString).Cast<Match>().ToList();
    Hope this will help you.
    Shashikant Gurav[Programmer II]

  • #764561
    I think the best way to split with space is to use 'null' as splitting parameter
    see below snippet
    string[] ssize = myStr.Split(null);

    string[] ssize = myStr.Split(new char[0]);

    according to MSDN
    If the separator parameter is null or contains no characters, white-space characters are assumed to be the delimiters. White-space characters are defined by the Unicode standard and return true if they are passed to the Char.IsWhiteSpace method.

    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #764575

    You can use split function available in

    Dim TestString As String = "Dhiraj"97987"Solanki"
    ' Returns an array containing "Dhiraj", "97987","Solanki".
    Dim TestArray() As String = Split(TestString)

    This will return an array.
    Inform me if you still not get the output.

    Dhiraj C. Solanki

  • Sign In to post your comments