c# - Strange behavior string.Trim method -


i want remove spaces(only ' ' , '\t', '\r\n' should stay) string. have problem.

example: if have

string test = "902322\t\r\n900657\t\r\n10421\t\r\n"; string res = test.trim(); // res still "902322\t\r\n900657\t\r\n10421\t\r\n"  res = test.trim('\t'); // res still "902322\t\r\n900657\t\r\n10421\t\r\n"  

but if have

string test = "902322\t"; 

trim() work perfectly. why behavior? how can remove '\t' string using trim() method?

string.trim method deals whitespaces @ beginning , end of string

so should use string.replace method

string test = "902322\t\r\n900657\t\r\n10421\t\r\n"; string res = test.replace("\t", string.empty); // res "902322\r\n900657\r\n10421\r\n"  

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -