Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's possible with regex but LINQ to XML is simpler. I've included LINQ to XML and a regex solution, although I would favor the former.</p> <p>Here's the LINQ to XML approach. Since <code>ul</code> is the top element its <code>Name</code> can be changed directly. <code>Descendants</code> will grab all the nested <code>ul</code> items. The only caveat with this approach is it only works if the input is well-formed. If it's wrong LINQ to XML will fail to parse it. Also, if it is well-formed and the <code>ul</code> isn't the top element but is part of a larger HTML block of text then you'll need to loop over <code>Elements("ul")</code> then do the same thing over each of them.</p> <p>If the HTML is malformed you may want to look at the <a href="http://htmlagilitypack.codeplex.com/" rel="nofollow noreferrer">HTML Agility Pack</a>.</p> <pre><code>Dim xml = XElement.Parse(input) xml.Name = "textformat" xml.SetAttributeValue("indent", "0") For Each item In xml.Descendants("ul") item.Name = "textformat" item.SetAttributeValue("indent", "20") Next </code></pre> <p>And here's the regex approach. It's not easy to detect the first <code>ul</code> item to distinguish between the two so this approach changes all of them to an indent of 20, then an extra step is taken to find the first <code>textformat</code> and change its indent to zero.</p> <pre><code>Dim pattern As String = "&lt;ul&gt;|&lt;/ul&gt;" Dim result As String = Regex.Replace(input, pattern, Function(m) If(m.Value.StartsWith("&lt;/"), "&lt;/textformat&gt;", "&lt;textformat indent=""20""&gt;")) Dim firstTextFormatPattern As String = "^(?&lt;Start&gt;&lt;textformat\s+indent="")\d+?(?&lt;End&gt;""&gt;)" result = Regex.Replace(result, firstTextFormatPattern, "${Start}0${End}") </code></pre>
    singulars
    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