Table of Contents

About

These functions convert from a key-value data string to a comma-separated value string.

Code

C#

///////////////////////////////////////////////////////////////////////////
//    Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0    //
///////////////////////////////////////////////////////////////////////////
/// <summary>
///     Converts key-value data to a comma-separated value string.
/// </summary>
/// <param name="kvp">a key-value data string</param>
/// <returns>a comma-separated value string</returns>
/// <remarks>compliant with RFC 4180</remarks>
public static string wasKeyValueDataToCSV(string kvp)
{
    List<string> csv = new List<string>();
    foreach (string n in kvp.Split('&'))
    {
        foreach (string s in n.Split('='))
        {
            List<char> cell = new List<char>();
            foreach (char i in s)
            {
                cell.Add(i);
                switch (!i.Equals('"'))
                {
                    case false:
                        cell.Add(i);
                        break;
                }
            }
            switch (!cell.Contains('"') && !cell.Contains(' ') && !cell.Contains(',') && !cell.Contains('\r') &&
                !cell.Contains('\n'))
            {
                case false:
                    cell.Insert(0, '"');
                    cell.Add('"');
                    break;
            }
            csv.Add(new string(cell.ToArray()));
        }
    }
    return string.Join(",", csv.ToArray());
}

fuss/data_structures/comma_separated_values/key-value_pairs/from.txt ยท Last modified: 2022/04/19 08:28 by 127.0.0.1

Access website using Tor Access website using i2p Wizardry and Steamworks PGP Key


For the contact, copyright, license, warranty and privacy terms for the usage of this website please see the contact, license, privacy, copyright.