c# - 在一些文本后面放置一个 <br/> 标签

标签 c# html string stringbuilder

我有一个变量 str,其中有一些文本。我只是在我的用户界面上显示此文本。 但我有一个条件,假设这个变量有 5oo 个单词,所以我需要在每 50 个单词后面放置一个
标签。

我怎样才能做到这一点?

下面是我的 C# 代码,我通过它以 html 形式发送邮件

Emailbody += " <tr>";
Emailbody += " <td align='left' valign='Top' nowrap><span class=style17>Purpose of     travel</span></td>";
Emailbody += "<td align='center' valign='Top'>:</td>";
Emailbody += " <td align='left' valign='Top'><span class=style17>&nbsp;&nbsp;" + TextBox1.Text +     "</span></td>";
Emailbody += " <td>&nbsp;</td>";
Emailbody += "  <td align='left' nowrap'><span class=style17>Advance</span></td>";
Emailbody += " <td align='center'>:</td>";
Emailbody += "<td align='left' nowrap><span class=style17>"+TextBox2.Text+"</td>";
Emailbody += " </tr>";

我需要 mt TextBox1.Text 的解决方案

最佳答案

如果您使用 C#,那么您可以这样做:

    public string SplitLine(string input)
    {
        var wordList = input.Split(' ');
        var sb = new StringBuilder();
        for (int index = 0; index < wordList.Length; index++)
        {
            if(index % 50 == 0 && index > 0)
                sb.Append("<br/>" + wordList[index]);
            else
                sb.Append(wordList[index] + ' ');
        }
        return sb.ToString();
    }

关于c# - 在一些文本后面放置一个 <br/> 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16557463/

相关文章:

c# - 使用 mysqldataadapter 归档时设置数据表的列默认值

c# - 如何知道点击了什么Linklabel?

c# - 使用模块基地址读取内存

css - 基金会 : margin between columns

html - 如何为 div 创建如下所示的曲线

c# - 将jp2的byte[]转为jpg文件

html - CSS:如何在固定宽度、居中的 div 的背景中显示图像?

Python 在 Print 语句中打印和乘以字符串

c++ - 为什么不能像这样复制 char 数组 charArray ="some string";

javascript - 使用正则查找字符串中元素的最后一个索引并删除子字符串