我有一个变量 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> " + TextBox1.Text + "</span></td>";
Emailbody += " <td> </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/