Table of Contents

About

Decodes a string of key-value pairs from data and returns a comma separated string of keys and values. Note that keys will be in the even positions and values in the odd positions, such that if $x$ is the index of a key, its corresponding value will be at index $x+1$ in the resulting string.

Example Usage

When the function is called with:

wasKeyValueToCSV("position=<1,1,0>&toggle=on");

it will return the string:

"position", "<1,1,0>", "toggle", "on"

Code

LSL

This script was tested and works on OpenSim version 0.7.4!

///////////////////////////////////////////////////////////////////////////
//    Copyright (C) 2013 Wizardry and Steamworks - License: CC BY 2.0    //
///////////////////////////////////////////////////////////////////////////
string wasKeyValueToCSV(string data) {
    return llList2CSV(llParseString2List(data, ["&", "="], []));
}

C#

///////////////////////////////////////////////////////////////////////////
//    Copyright (C) 2014 Wizardry and Steamworks - License: CC BY 2.0    //
///////////////////////////////////////////////////////////////////////////
/// <summary>
///     Serialises key-value tuples from data to comma-separated values.
/// </summary>
/// <param name="data">the data containing key-value pairs</param>
/// <returns>a comma-separated string</returns>
private static string wasKeyValueToCSV (string data)
{
	return string.Join (",",
		data.Split ('&')
		.Select (p => p.Split ('=')).SelectMany (p => p)
		.ToArray ());
}

fuss/data_structures/key-value_pairs/csv/to.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.