gpt4 book ai didi

c# - 在 C# 代码隐藏中修剪字符串

转载 作者:太空狗 更新时间:2023-10-30 00:01:19 26 4
gpt4 key购买 nike

我的代码隐藏中有这一行:

lblAboutMe.Text = (DT1["UserBody"].ToString());

没问题。但是现在,我们只想显示段落的开头,然后是省略号。所以,而不是:

Please read it all as I hate wasting time with people that don't. If you have an issue with Muslim's please move on as I do not. I used to practice Islam and while I no longer do I still respect it and hate the ignorance people show by following the media or stigma instead of experiencing it or talking with Muslim's to educate themselves about it. Referring to the no drug policy later in this profile, yes, pot/marijuana counts as a drug and is a no with me so please move on. I know what follows makes me seem cold but I am really quite warm and loving, very devoted to the right one, i am just tired of being played and taken for granted/ advantage of. People lie soooo much and ignore so much of what I say I do not want. I have been told many times on here that what I seek is too much.

我们只想取前 100 个字符并在其后加上省略号。所以,像这样:

Please read it all as I hate wasting time with people that don't. If you have an issue with Muslim's please move on as I do not. I used to practice Islam and while I no longer do I still respect it and hate the ignorance people show by following the media or stigma instead of experiencing it or talking with Muslim's to educate themselves ...

我们如何在代码隐藏中做到这一点?我感觉这很容易(因为在 Access 中会很容易),但我对这种语言还是陌生的。

最佳答案

使用 Length 确定您的 string 长度,如果太长则使用 Substring 取其中的一些(100 个字符):

string aboutme = DT1["UserBody"] != null ? DT1["UserBody"].ToString() : ""; //just in case DT1["UserBody"] is null
lblAboutMe.Text = aboutme.Length > 100 ? aboutme.Substring(0,100) + "..." : aboutme;

关于c# - 在 C# 代码隐藏中修剪字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35078040/

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