Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

removing single quote from end of a string in C#

Tags:

c#

i am using the following code :

  importTabs.Add(row["TABLE_NAME"].ToString().TrimEnd('$')

to remove a dollar from string stored in importTabs Array list. how do i pass a parameter along with '$' so that it removes a single quote (') from the beginning ans well the end of the string?

like image 467
CarbonD1225 Avatar asked Dec 06 '22 14:12

CarbonD1225


2 Answers

You could use another trim:

importTabs.Add(row["TABLE_NAME"].ToString().Trim('\'').TrimEnd('$')

Or, if you don't mind removing the $ at the beginning too, you can do it all at once:

importTabs.Add(row["TABLE_NAME"].ToString().Trim('\'', '$')

That saves you from creating one more string instance than you need to.

like image 134
vcsjones Avatar answered Dec 21 '22 23:12

vcsjones


I would use trim twice

importTabs.Add(row["TABLE_NAME"].ToString().Trim('\'').TrimEnd('$')
like image 32
Aeropher Avatar answered Dec 22 '22 00:12

Aeropher