-3

If I copy " BOB3 27QK DEPM PJ7J T25G SJZI CJA5 BO5O|123456 " and I want to pass it to my text box, and get only the last 6 digits number in my text box, How to do in c#?

2 Answers2

2

Using .Split would look like this:

string myString = "BOB3 27QK DEPM PJ7J T25G SJZI CJA5 BO5O|123456";
        char[] mySplitChars = { '|' };
        string[] myArray = myString.Split(mySplitChars);
        Console.WriteLine(myArray[1]);

Using .Substring would look like this:

Console.WriteLine(myString.Substring(myString.Length - 6));

The latter is probably preferred because it is shorter and it does not rely on the "|" character being present. The former would be preferred if the "|" is always present but the number of characters at the end can change.

Terry Tyson
  • 629
  • 8
  • 18
0

How are you passing it your text box? If it's just getting the last n characters: refer to this answer