Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将文本内容从数据库分割为段落_C#_Html_Asp.net Mvc - Fatal编程技术网

C# 将文本内容从数据库分割为段落

C# 将文本内容从数据库分割为段落,c#,html,asp.net-mvc,C#,Html,Asp.net Mvc,我在数据库中存储了一张文本图片: 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 dr

我在数据库中存储了一张文本图片:

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(Model.Products中的变量项)
{
@项目1.动物图片
-@item.anotherimage-


@item.Description您没有解释要使用的除法算法。 这段代码将把你所有的单词分成几段

string[] words = Text.Split(' ');
@foreach( string word in words )
    <p> @word </p>
string[]words=Text.Split(“”);
@foreach(单词中的字符串)
@word

使用您的模型。说明而不是文本字符串

编辑: 在相应位置使用此代码

@{
    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>
    }
}
@{
string[]words=item.description.Split(“”);
int-wordsPerLine=25;
for(int i=0;i
}
}

Hmm..I尝试使用您的代码时出错..可能是因为我已经在foreach中了?请查看我的编辑!您想为每个项目或您想做的事情划分描述吗?假设@item.Description包含一个100字的字符串。我想将每个25字拆分为一个新段落。您想在我创建时对每个项目执行此操作吗从上面的代码中理解了吗?不…只针对@item.Description…其他两个项目是图像…所以我想我应该在第一个项目中使用另一个foreach?
@{
    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>
    }
}