How do I remove whitespace at the beginning of my

2019-07-29 05:16发布

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

8条回答
The star\"
2楼-- · 2019-07-29 05:28

test.trim();
This method removes whitespaces from beginning and ending of the string.

查看更多
霸刀☆藐视天下
3楼-- · 2019-07-29 05:28

Speaking of Java: String.trim(). Here is the link to the API documentation: String.trim()

查看更多
我想做一个坏孩纸
4楼-- · 2019-07-29 05:40

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:


string trimmed = test.Trim();
// or
string trimmed = test.TrimStart();

查看更多
叼着烟拽天下
5楼-- · 2019-07-29 05:51

you can use TrimStart in C#:

string test2 = test.TrimStart()
查看更多
家丑人穷心不美
6楼-- · 2019-07-29 05:52

You can use:

All these have additional overloads which let you specify an array of custom characters also to be removed.

查看更多
beautiful°
7楼-- · 2019-07-29 05:52

I can also use the method TrimStart()

like this:

string test2 = test.TrimStart(' ');

查看更多
登录 后发表回答