开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜