string to dictionary

CSharp · Console

/Program.cs

using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        string input = "value1/672/value2/32/value3/21413";
        string[] parts = input.Split('/');
        var dictionary = parts
            .Select((value, index) => new { value, index })
            .Where(x => x.index % 2 == 0) // Select only even value elements as keys
            .ToDictionary(x => x.value, x => parts[x.index + 1]); // Use the value element as value      
        
		foreach (var kvp in dictionary)   // Loop for printing the result only
        {
            Console.WriteLine($"{kvp.Key}: {kvp.Value}");   // Output the dictionary key and values
        }
    }
}
;