) ...">

Removing a single quote from the end of a line in C #

I am using the following code:

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

to remove the dollar from the string stored in the importTabs array list. How to pass a parameter along with '$' so that it removes one quote (') from the beginning and end of the line?

+4
source share
3 answers

You can use another trim:

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

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

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

This will save you from creating another instance of the string than you need.

+10
source

I would use a trimmer twice

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

Not sure if I fully understand your question. Do you want to remove single quotes from the beginning and end and remove $ from the end? If so, you can use this ...

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

If the $ sign is in front of the final tic label, then Trims must be reversed ...

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

If you know that there is no $ sign at the beginning, you can simplify it ...

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

If you want to pass it as a parameter, Trim takes an array of characters

 char[] charactersToRemove = new[] {'$', '\''}; importTabs.Add(row["TABLE_NAME"].ToString().Trim(charactersToRemove)) 
0
source

Source: https://habr.com/ru/post/1414176/


All Articles