开发者

How can I remove a space, multiple space or tab from the start of a string in C#

开发者 https://www.devze.com 2023-03-30 09:14 出处:网络
I have strings in a file that I read. Some have space(s) or tabs at the start. Is there an easy way I can remove the space and tab (whitespace stuff)?

I have strings in a file that I read. Some have space(s) or tabs at the start. Is there an easy way I can remove the space and tab (whitespace stuff)?

For example

var abc = "   def";

What I want is to remove the things before the "def".

thanks,

Update: I believe this is the correct answer:

ch开发者_开发知识库ar[] arr = new char[] { '\t', ' ' }; // Trim these characters
text = text.TrimStart(arr);


Use string.TrimStart():

var result = abc.TrimStart();


Use the built in String methods.

abc.Trim()


Just use the Trim method

abc.Trim()
0

精彩评论

暂无评论...
验证码 换一张
取 消