[RESOLVED]capture 3 words only

i have long description of 150 words. But i would like to capture first 3 words only using razor coding.

Example:

150 word description

"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco

Expected result

Lorem ipsum dolor

@{
    string description = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco";
    string[] words = description.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
}
<p>
    @(words.Length > 3 ? string.Join(" ", words.Take(3)) : string.Join(" ", words))
</p>

ssvikramuk

"only using razor coding"

Not possible. That is something you do with c# if your pages are .cshtml

Leave a Reply