开发者

How to Remove Last digit of String in .Net?

I want to eliminate B if i scan Serial number bar code: 21524116476CA2006765B

开发者_StackOverflowOutput: 21524116476CA2006765


string foo = "21524116476CA2006765B";
string bar = foo.Substring(0, Math.Max(foo.Length - 1, 0));


If you can't be certain that the input barcode will always end with a B, do something like this:

char[] barcodeEnd = { 'B' };

string input = "21524116476CA2006765B";
string output = input.TrimEnd(barcodeEnd);

PUt the first line somewhere it'll only get run once, so you aren't constantly creating new char[] arrays. You can add more characters to the array if you're looking for other specific characters.


string s = "21524116476CA2006765B";
string b = s.Substring(0, s.Length - 1);


string value= "21524116476CA2006765B";
string bar = value.Substring(0, 19);


string str = "Your String Whatever it is";
str = str.Substring(0, s.Length - 1);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜