比如一个字符串“<label id='label1'><label id='label1'><label id='label1'><label id='label1'><label id='label1'>”
需要在每个label前增加一个分隔符‘|’
要求用asp.net实现
谢谢!

解决方案 »

  1.   

    public string encodeString="<label id='label1'> <label id='label1'> <label id='label1'> <label id='label1'> <label id='label1'>";
    public static string HtmlEncode(encodeString)
    {
    encodeString = encodeString.Replace("<", "|<");
    return encodeString;
    }
      

  2.   


    public string HtmlEncode() 

    StrHtml=" <label id='label1'> <label id='label1'> <label id='label1'> <label id='label1'> <label id='label1'>"; 
    StrHtml= StrHtml.Replace(">", ">|");  做替换把> 替换为>|
    如果需要的话! 你还可以把最后1个|移除掉
    StrHtml = StrHtml.substring(0,StrHtml.length-1)
    return StrHtml; 
    }
      

  3.   


    string value="<label id='label1'> <label id='label1'> <label id='label1'> <label id='label1'> <label id='label1'>";
                int groupcount = System.Text.RegularExpressions.Regex.Matches(value, @"<label id='label1'>").Count;
                string tempValue=value;
                for (int j = 0; j < groupcount; j++)
                {
                    int i = tempValue.LastIndexOf("<label id='label1'>");
                    tempValue = value.Substring(0, i);
                    if (i > 0)
                    {
                        value=value.Insert(i, "|");
                    }
                }
                Response.Write(value);
      

  4.   

    public string HtmlEncode() 

    StrHtml=" <label id='label1'> <label id='label1'> <label id='label1'> <label id='label1'> <label id='label1'>"; 
    StrHtml= StrHtml.Replace(">", ">|");  
    StrHtml = StrHtml.TrimEnd("|");
    return StrHtml;