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
Post a Comment