I have a line like this:
string val = 555*324-000
now I need to remove the * and - characters, so I use this code ( based on MSDN )
char[] CharsToDelete = {'*', '(', ')', '-', '[', ']', '{', '}' }; string result = val.Trim(CharsToDelete);
but the string remains unchanged. What reason?
Trim ... Removes all leading and trailing occurrences of the character set specified in the array from the current String object. Instead, you should use a replacement method.
Since Trim () will delete any character in CharsToDelete at the beginning and end of the line.
You should use the val.Replace () function.
:
string val = 555*324-000 char[] CharsToDelete = {'*', '(', ')', '-', '[', ']', '{', '}' }; foreach (char c in CharsToDelete) { val = val.Replace(c, ''); }
Source: https://habr.com/ru/post/1754575/More articles:Как создать ветку из тега SVN с Maven? - branchC #: AsyncCallback not called on Socket.BeginReceive - c #How to get full production.log from rails application in heroku? - ruby-on-railsHow to show files that were merged without fast forward in Git? - gitDatabase source code versus schema change scripts - version-controlTransfer changes from Dev DB to production database - version-controlПреобразование double to decimal - decimalTracking changes to class instances and their associations - thoughts? - ruby-on-railsPage Break EPUB ebook - paginationHow can we use mysql restrictions with iBatis in general? - mysqlAll Articles