Remove last character using TrimEnd()


You somehow create  an array using a loop  and want to sperate items with comma or etc. but everyone knows the last char of this array is one of that comma and unwant.You have to remove it. Usually we do this like

string mystring = “some,thing,in,this,array,”;

   mystring = mystring.Substring(0, mystring.Length - 1);

this is correct bu there is an easy way to do it:

   mystring = mystring.TrimEnd(',');
Advertisement

About bpostaci
Escalation Engineer in Microsoft.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: