Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Remove penultimate character in a string

Posted on 2007-08-09
2
Medium Priority
?
561 Views
Last Modified: 2013-11-05
Hi

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?
0
Comment
Question by:JakeyCakes
2 Comments
 
LVL 3

Accepted Solution

by:
DelTreme earned 2000 total points
ID: 19660968
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 + "");
0
 

Author Comment

by:JakeyCakes
ID: 19661008
DelTreme,

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.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question