Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>this exercise does what you need utilizing regular expressions.</p> <p>This is how it works: I do not replace values in the original string. Instead, I take the goal string, where we want to arrive to, and build it with the correct values. I believe that this approach will give you flexibility, you can format the output string however you want.</p> <ul> <li>The inputList is a list of test cases.</li> <li>The target is the goal string with placeholders, we can format it however we want/need/have to.</li> <li>The GetValue() method utilizes the regex argument to seek for an specific value. It finds the html tag as a KeyValue pair, it takes the Value and removes the enclosing quotes.</li> <li>Finally with the string.Format() we build the output string as desired.</li> </ul> <p>It is full code, so you can try it. You can also turn the idea of this piece of code into a method an integrate it in your solution.</p> <p>Please let me know if it worked for you too.</p> <pre><code> static void Main(string[] args) { List&lt;string&gt; inputList = new List&lt;string&gt;(); inputList.Add("&lt;input type=\"radio\" name=\"eq_9\" id=\"eq_9_2\" onclick=\"nextStepID_load(this);\" value=\"Installer.\" title=\"912\" /&gt;&lt;label for=\"eq_9_2\"&gt;Installer&lt;/label&gt; &lt;br /&gt;"); inputList.Add("&lt;input type=\"radio\" name=\"eq_10\" id=\"eq_9_3\" onclick=\"nextStepID_load(this);\" value=\"Installer1.\" title=\"913\" /&gt;&lt;label for=\"eq_9_3\"&gt;InstallerA&lt;/label&gt; &lt;br /&gt;"); inputList.Add("&lt;input type=\"radio\" name=\"eq_11\" id=\"eq_9_4\" onclick=\"nextStepID_load(this);\" value=\"Installer2.\" title=\"914\" /&gt;&lt;label for=\"eq_9_4\"&gt;InstallerB&lt;/label&gt; &lt;br /&gt;"); inputList.Add("&lt;input type=\"radio\" name=\"eq_12\" id=\"eq_9_5\" onclick=\"nextStepID_load(this);\" value=\"Installer3.\" title=\"915\" /&gt;&lt;label for=\"eq_9_5\"&gt;InstallerC&lt;/label&gt; &lt;br /&gt;"); inputList.Add("&lt;input type=\"radio\" name=\"eq_13\" id=\"eq_9_6\" onclick=\"nextStepID_load(this);\" value=\"Installer4.\" title=\"916\" /&gt;&lt;label for=\"eq_9_6\"&gt;InstallerD&lt;/label&gt; &lt;br /&gt;"); string output = string.Empty; string target = "&lt;button type=\"button\" name=\"{0}\" id=\"{1}\" onclick=\"nextStepID_load('{2}');\"&gt;{3}&lt;/button&gt;&lt;br /&gt;"; foreach (string input in inputList) { string name = GetValue(@"(?&lt;Value&gt;name=[\S]+)", input); string id = GetValue(@"(?&lt;Value&gt;id=[\S]+)", input); string title = GetValue(@"(?&lt;Value&gt;title=[\S]+)", input); string value = GetValue(@"(?&lt;Value&gt;value=[\S]+)", input); output = string.Format(target, name, id, title, value); System.Diagnostics.Debug.WriteLine(output); } } private static string GetValue(string pattern, string input) { Regex regex = new Regex(pattern); Match match = regex.Match(input); return match.ToString().Split('=').Last().Replace("\"", string.Empty); } </code></pre> <p>this is the input:</p> <pre><code> &lt;input type="radio" name="eq_9" id="eq_9_2" onclick="nextStepID_load(this);" value="Installer." title="912" /&gt;&lt;label for="eq_9_2"&gt;Installer&lt;/label&gt; &lt;br /&gt; &lt;input type="radio" name="eq_10" id="eq_9_3" onclick="nextStepID_load(this);" value="Installer1." title="913" /&gt;&lt;label for="eq_9_3"&gt;InstallerA&lt;/label&gt; &lt;br /&gt; &lt;input type="radio" name="eq_11" id="eq_9_4" onclick="nextStepID_load(this);" value="Installer2." title="914" /&gt;&lt;label for="eq_9_4"&gt;InstallerB&lt;/label&gt; &lt;br /&gt; &lt;input type="radio" name="eq_12" id="eq_9_5" onclick="nextStepID_load(this);" value="Installer3." title="915" /&gt;&lt;label for="eq_9_5"&gt;InstallerC&lt;/label&gt; &lt;br /&gt; &lt;input type="radio" name="eq_13" id="eq_9_6" onclick="nextStepID_load(this);" value="Installer4." title="916" /&gt;&lt;label for="eq_9_6"&gt;InstallerD&lt;/label&gt; &lt;br /&gt; </code></pre> <p>this is the output:</p> <pre><code> &lt;button type="button" name="eq_9" id="eq_9_2" onclick="nextStepID_load('912');"&gt;Installer.&lt;/button&gt;&lt;br /&gt; &lt;button type="button" name="eq_10" id="eq_9_3" onclick="nextStepID_load('913');"&gt;Installer1.&lt;/button&gt;&lt;br /&gt; &lt;button type="button" name="eq_11" id="eq_9_4" onclick="nextStepID_load('914');"&gt;Installer2.&lt;/button&gt;&lt;br /&gt; &lt;button type="button" name="eq_12" id="eq_9_5" onclick="nextStepID_load('915');"&gt;Installer3.&lt;/button&gt;&lt;br /&gt; &lt;button type="button" name="eq_13" id="eq_9_6" onclick="nextStepID_load('916');"&gt;Installer4.&lt;/button&gt;&lt;br /&gt; </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.
    1. VO
      singulars
      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