tags:

views:

149

answers:

5

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

Output: 21524116476CA2006765

+3  A: 
string foo = "21524116476CA2006765B";
string bar = foo.Substring(0, Math.Max(foo.Length - 1, 0));
LukeH
Yup.I only want to remove the letter B. or the last digit.And i only want to capture the first 20 digit. ") Thanks for your replies. i will try it now.
Crimsonland
why don't you accept an answer instead of leaving your accept rate at 0% ?
rockinthesixstring
A: 

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.

Warren
Yup.I only want to remove the letter B. or the last digit.And i only want to capture the first 20 digit. ") Thanks for your replies. i will try it now.
Crimsonland
A: 
string s = "21524116476CA2006765B";
string b = s.Substring(0, s.Length - 1);
freak
A: 
string value= "21524116476CA2006765B";
string bar = value.Substring(0, 19);
Ram
A: 
string str = "Your String Whatever it is";
str = str.Substring(0, s.Length - 1);
Johnny