gpt4 book ai didi

c# - 如果单词比 X 长,则用点替换字符串的结尾

转载 作者:行者123 更新时间:2023-11-30 13:22:55 25 4
gpt4 key购买 nike

如果字符串长于 X 个字符,我如何在 Razor CSHTML 页面中格式化字符串:

<p>@Model.Council</p> 

Example for an X = 9

-> if Council is "Lisbon", then the result is "<p>Lisbon</p>"
-> if Council is "Vila Real de Santo António", then the result is "<p>Vila Real...</p>" with the title over the <p> "Vila Real de Santo António" showing the complete information

谢谢。

最佳答案

对于任何字符串。 See here .

对于您的代码...

@(Model.Council.Length>10 ? Model.Council.Substring(0, 10)+"..." : Model.Council)

关于c# - 如果单词比 X 长,则用点替换字符串的结尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16765328/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com