Remove penultimate character in a string


As part of project I am working on I have to remove the penultimate digit from a six digit number (which I will not know). For example ,the number 922001 needs to become 92201.  It would seem to me that the best way to achieve this is by using string builder, but I can't get my string builder code achieve my goal.

Can anyone help?
Who is Participating?
Does this snippet work for you?

int number_in = 123456;
string strNumber = number_in.ToString();
while (strNumber.Length < 6) strNumber = "0" + strNumber;  // when the number starts with a 0
strNumber = strNumber.Substring(0, 4) + strNumber.Substring(5);
int number_out = int.Parse(strNumber);
System.Windows.Forms.MessageBox.Show(number_out + "");
JakeyCakesAuthor Commented:

You genius! It does what I want perfectly, and it seems so much more efficient than my idea I had after posting this question (I thought about using the Remove function in the stringbuilder class). The points are deservedly yours.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.