C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,307 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello,
I get this string back. Always with a carriage return. Do I have to create a key value from this? It's sure to be easy. Which is best?
String ret="Speed=300
Color=“Red“
Order=“35253256“
ProductID=342424
Price=“349 €“
Tax=“19%“
Electricity=2,55
Comment=“230V 2,55A“"
Goal
key = Color value = "Red"
key= Price value = 349 €
Hello @Markus Freitag
See if this works for you.
private void Demo()
{
var ret =
"Speed=300\nColor=\"Red\"\nOrder=\"35253256\"\n" +
"ProductID=342424\nPrice=\"349 €\"\nTax=\"19%\"\n" +
"Electricity=2,55\nComment=\"230V 2,55A\"";
var itemsList = ret.Split('\n').Select(item =>
{
var parts = item.Split('=');
return new {Key = parts[0], Value = parts[1]};
}).ToList();
var dict = new Dictionary<string, string>();
foreach (var line in itemsList)
{
dict.Add(line.Key, line.Value);
}
}