Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Firstly, I suggest you try to use a Dictionary or any other generic collection instead of an ArrayList to make it type-safe. Then use a string.Split(char c) and start the processing from there.</p> <p>Here's an idea on how you can do it. It might get shorter with Extension methods of course. But here's just a thought-process on how you can do it.</p> <pre><code> static void ParseSupplierIdWithProducts() { string supplierIdWithProducts = "1_1001,1_1002,20_1003,100_1005,100_1006"; //eg. [0] = "1_1001", [1] = "1_1002", etc List&lt;string&gt; supplierIdAndProductsListSeparatedByUnderscore = supplierIdWithProducts.Split(',').ToList(); //this will be the placeholder for each product ID with multiple products in them //eg. [0] = key:"1", value(s):["1001", "1002"] // [1] = key:"20", value(s):["1003"] Dictionary&lt;string, List&lt;string&gt;&gt; supplierIdWithProductsDict = new Dictionary&lt;string, List&lt;string&gt;&gt;(); foreach (string s in supplierIdAndProductsListSeparatedByUnderscore) { string key = s.Split('_')[0]; string value = s.Split('_')[1]; List&lt;string&gt; val = null; //look if the supplier ID is present if (supplierIdWithProductsDict.TryGetValue(key, out val)) { if (val == null) { //the supplier ID is present but the values are null supplierIdWithProductsDict[key] = new List&lt;string&gt; { value }; } else { supplierIdWithProductsDict[key].Add(value); } } else { //that supplier ID is not present, add it and the value/product supplierIdWithProductsDict.Add(key, new List&lt;string&gt; { value }); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload