我的数据库存储了一些文本:
model.Description : "Bacon ipsum dolor sit amet fatback pork belly swine cow drumstick jowl"
在我看来,我想把这样的文字分开:
<p>
Bacon ipsum dolor
</p>
<p>
sit amet fatback por
</p>
<p>
belly swine cow drumstick
</p>
我希望将文本划分为换行符。有没有办法实现这一目标? 它以后以任何可能的方式传播......
编辑:
@foreach (var item in Model.Products)
{
<div class="col-md-8">
<h4>@item.animage</h4>
<h5>- @item.anotherimage -</h5>
<br>
<p>
@item.Description <---This is the one to divide!
</p>
</div>
}
答案 0 :(得分:1)
您没有解释您想要使用的分割算法。 此代码会将您的所有单词划分为段落。
string[] words = Text.Split(' ');
@foreach( string word in words )
<p> @word </p>
使用您的model.Description而不是Text string
编辑: 在相应位置使用此代码
@{
string[] words = item.Descritpion.Split(' ');
int wordsPerLine = 25;
for (int i = 0; i < words.Length; )
{
<p>
@for (int j = 0; j < wordsPerLine && i < words.Length; i++, j++)
{
@words[i]
}
</p>
}
}