Let's say I have following string:
string test = " False";
I can't loop the characters of the string because I need to do this for 1744 strings, then it would be a lot of work.
Do you know if there is a method from Microsoft that I can use to delete this whitespace?
Like this: string test2 = test.DeleteFirstWhitespace();
Thanks
test.trim();
This method removes whitespaces from beginning and ending of the string.
Speaking of
Java
:String.trim()
. Here is the link to the API documentation:String.trim()
As everyone else has pointed out, there is a trim function. Make sure to remember that a string is immutable, so when you call test.Trim(), it will not modify the test variable, it will return a new string:
you can use
TrimStart
in C#:You can use:
All these have additional overloads which let you specify an array of custom characters also to be removed.
I can also use the method
TrimStart()
like this:
string test2 = test.TrimStart(' ');