Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I did it using LINQ... might not be the best way but it was fun to figure it out:</p> <pre><code>string test = "&lt;info:\"Enterprise Optimizer 7.4 for COR Technology 5.5 -- Advanced Solver Edition\", url:\"http://EO.riverlogic.com\", url_menu:\"EO Online...\", app_id:\"EOAS\",app_name:\"Enterprise Optimizer AS\", **app_major:7**, **app_minor:4**,**app_micro:5**,app_copyright:\"251 1996-2010 River Logic Inc.\r\nAll Rights Reserved.\"&gt;"; var result = test.Split(','). Select(p =&gt; p.Trim().Split(':')). Where(i =&gt; i[0].Trim().StartsWith("**app_")). Select(r =&gt; new { Key = r[0].Trim('*'), Value = r[1].TrimEnd('*') }); </code></pre> <p>Produces:</p> <pre><code>result = {{Key = "app_major", Value = "7"}, {Key = "app_minor", Value = "4"}, {Key = "app_micro", Value = "5"}} </code></pre> <p>It could probably even be done much more elegantly :)</p> <p><strong>EDIT:</strong> If you want to make it very simple to access what you want do:</p> <pre><code>var result = test.Split(','). Select(p =&gt; p.Trim().Split(':')). Where(i =&gt; i[0].Trim().StartsWith("**app_")). Select(r =&gt; new { Key = r[0].Trim('*'), Value = r[1].TrimEnd('*') }). ToDictionary(k =&gt; k.Key, v =&gt; v.Value); </code></pre> <p>Then to get the value out just give it the key like this:</p> <pre><code>var version = result["app_major"] ?? "Not Found"; </code></pre> <p>Note I have tested the LINQ solution vs the Regex solution and the LINQ version is not that much of a difference in terms of speed but it is a bit slower than the regex answers posted. The regex answer though do not clean the data for you and present it in a easy to use manner. The <code>ToDictionary</code> part really slows it down (in terms of real time though it is almost nothing still) but it does make the results easier to use.</p>
 

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