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(',');
Advertisements

About bpostaci
Sr. Support 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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: