对 HTML 列表的字符串操作

String manipulation to HTML list

我有这个string:

var audit = "Id:1;Name:John;Address:|||Id:123;Street:123 Main St.;City:LA;State:|||Id:234;Name:California;Code:CA|||;ZipCode:12345|||;IsActive:true";

如何把它变成:

<ul>
    <li>Id: 1<li>
    <li>Name: John<li>
    <li>
       Address: 
       <ul>
           <li>Id: 123<li>
           <li>Street: 123 Main St.<li>
           <li>City: LA<li>
           <li>
              State: 
              <ul>
                  <li>Id: 234<li>
                  <li>Name: California<li>
                  <li>Code: CA<li>
              </ul>
           <li>
           <li>ZipCode: 12345</li>
       </ul>
    <li>
    <li>IsActive: true<li>
</ul>

现在我正在使用 ViewHelper 但它在处理 ||| 东西时完全失败:

@helper ChangedDisplay(string changed)
{
    if (string.IsNullOrEmpty(changed) || changed.Trim().ToLower() == "n/a")
    {
        @:n/a
    }
    else
    {
       var rows = changed.Split(';');

       <ul>
            @foreach (var row in rows)
            {
                var columns = row.Split(':');
                <li>
                    @(columns.First()): 
                    @if (columns.Last().Contains("|||"))
                    {
                        @ChangedDisplay(columns.Last().Trim('|'))
                    }
                    else
                    {
                        @columns.Last()
                    }
                </li>
            }
        </ul>
    }
}

感谢您的帮助。

像这样:

        audit = "Id:1;Name:John;Address:|||Id:123;Street:123 Main St.;City:LA;State:|||Id:234;Name:California;Code:CA|||;ZipCode:12345|||;IsActive:true";


        var auditHtml = "<ul><li>" + audit
            .Replace("|||;", "</li></ul><li>")
            .Replace(":|||", ":<ul><li>")
            .Replace(";", "</li><li>")
            + "</li></ul>"
        ;