A few months back i was caught in situation where we had special characters in data base like shift+enter, tab , space , enter etc.
That time we spend 3 hours to detect issue and next 3 hours to resolve it. But a few days back one of my colleague get caught in same situation we helped her to detected the issue and suggested the same solution we put at that time, but somehow she managed to get more easy approach to resolve the issue.
so if a string has special characters in it, then it is better approach to change value to string and than perform a trim on the charcter we want to remove.
for eg:
string s= dr.GetString("column1");
assuming s contains a tab and enter character in it.
s=s.ToString().Trim("\t"); // it will remove tab character form string
s=s.ToString().Trim("\n"); // it will remove enter character from string
so it is better to use Trim instead of performing looping on character and using ASCII to remove character.
Note: But remember, you need to use ToString method before using Trim method. If we wont do that there wont be any affect on string.
Happy Living....
Happy Concepts....
Happy Programming....
That time we spend 3 hours to detect issue and next 3 hours to resolve it. But a few days back one of my colleague get caught in same situation we helped her to detected the issue and suggested the same solution we put at that time, but somehow she managed to get more easy approach to resolve the issue.
so if a string has special characters in it, then it is better approach to change value to string and than perform a trim on the charcter we want to remove.
for eg:
string s= dr.GetString("column1");
assuming s contains a tab and enter character in it.
s=s.ToString().Trim("\t"); // it will remove tab character form string
s=s.ToString().Trim("\n"); // it will remove enter character from string
so it is better to use Trim instead of performing looping on character and using ASCII to remove character.
Note: But remember, you need to use ToString method before using Trim method. If we wont do that there wont be any affect on string.
Happy Living....
Happy Concepts....
Happy Programming....