开发者

How to Remove Last digit of String in .Net?

开发者 https://www.devze.com 2022-12-30 14:32 出处:网络
I want to eliminate B if i scan Serial number bar code: 21524116476CA2006765B 开发者_StackOverflowOutput: 21524116476CA2006765string foo = \"21524116476CA2006765B\";

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

精彩评论

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