In this example, i’ll show you How to trim the last character of a string in C# Windows Form Application.
C# Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
private void button1_Click(object sender, EventArgs e) { //this section create a string variable. string plants = "csharp examples"; label1.Text = "string of plants : " +plants+ Environment.NewLine; //this line remove/delete/trim last character from string. string trimmedLastCharacter = plants.TrimEnd(plants.Last()); label1.Text += "plants after trim last character: "; label1.Text += trimmedLastCharacter; } |
Output: