字符串c#的修剪开头

问题描述 投票:0回答:1

是否可以仅修剪字符串的开头?I ve used .Trim,but it removes the characters from beginning and from the end of the string. I want to have different imputs in binary,and to remove all the 0从字符串的开头开始(例如:00100变为100)。在我的代码中,0100将变为1,因为.Trim会删除0s from the end of the string. How can I fix it?I dont,因为它知道输入是以0开头还是以0开头。

string n = Console.ReadLine();
res = x.Trim(new[] { '0' });
c# string trim
1个回答
0
投票

是,您可以使用String.TrimStart

string n = Console.ReadLine();
res = x.TrimStart('0');
© www.soinside.com 2019 - 2024. All rights reserved.