![](/img/trans.png)
[英]C# How can I paste formatted text from clipboard to the RichTextBox
[英]How to paste formatted text in textbox, C#
我試圖將一些電子郵件粘貼到每個電子郵件末尾帶有分號(;)的大型文本框中,但我不希望分號位於最后一封電子郵件的末尾。 請我該怎么做,所有答案都將受到歡迎。
您可以使用TrimEnd()
函數
string Emails = "me@email.com;metoo@email.com;";
this.textBox1.Text = Emails.TrimEnd(';');
或者它已經在您的TextBox中
this.textBox1.Text = this.textBox1.Text.TrimEnd(';');
嘗試這個
string email = "metoo@email.com;abc@email.com;xyz@email.com;";
this.textBox1.text = email.Replace(";", string.Empty);
//to show emails in separate lines then use it in this way
this.textBox1.text = email.TrimEnd(';').Replace(";", Environment.NewLine);
只需刪除最后一個字符。 您可以使用子字符串來實現。
我不明白你想要什么 但是也許這段代碼可以幫助您刪除最后一個分號(如果存在)。
var str = "email@email.com;email2@email.com;email3@email.com;";
var length = str.Length - 1;
if (str.LastIndexOf(';') == length)
{
str.Remove(length);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.