简体   繁体   English

如何在C#文本框中粘贴格式化的文本

[英]How to paste formatted text in textbox, C#

am trying to paste some emails into a large textbox with a semi-colon(;) at the end of each email but i don't want the semi-colon to be at the back of the last email. 我试图将一些电子邮件粘贴到每个电子邮件末尾带有分号(;)的大型文本框中,但我不希望分号位于最后一封电子邮件的末尾。 Please how can i go about this, all answers would be welcomed. 请我该怎么做,所有答案都将受到欢迎。

You can use the TrimEnd() function 您可以使用TrimEnd()函数

string Emails = "me@email.com;metoo@email.com;";
this.textBox1.Text = Emails.TrimEnd(';');

or if it's already in your TextBox 或者它已经在您的TextBox中

this.textBox1.Text = this.textBox1.Text.TrimEnd(';');

Try this 尝试这个

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);

Just remove the last char. 只需删除最后一个字符。 You can do that with a substring. 您可以使用子字符串来实现。

I don't understand what do you want. 我不明白你想要什么 But maybe this code can help you to remove the last semi-colon if it exists. 但是也许这段代码可以帮助您删除最后一个分号(如果存在)。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM