Hello,
My problem is, I am trying to format a number into a certian format.

The number is 100072305608500 (this is the exact copy from what was passed in)

the format it should be in is 100/07-23-056-08W5/00

I am using

return (string.Format("{##0/00-00-000-00W0/##}}", Convert.ToInt64(wellLocation)));

where the # are optional digits.
I keep getting an error "Format Exception was unhandled Input string was not in correct format.

Any help is appreciated.

Thanks in advance.

Recommended Answers

All 4 Replies

This works for me.

long number = 100072305608500L;
string format = "##0/00-00-000-00W0/##";
string output = number.ToString(format);

Leave out the curly braces in your format.
Tried this and it worked:

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Int64 i = 100072305608500;
            Console.WriteLine(i.ToString(string.Format("##0/00-00-000-00W0/##")));
            Console.ReadKey();
        }
    }
}

Thank you very much! I have it working now with your help. The funny thing is, I have a prevoiuse one for a different number working

return (string.Format("{0:##-00-000-00W0}}", Convert.ToInt32(wellLocation)));

but I couldnt get this one working.

Thanks again.

Hi!

the error in your posted codeline is, that there are to much closing braces }}

try this:

return (string.Format("{0:##-00-000-00W0}", Convert.ToInt32(wellLocation)));

hope this helps
Daniel

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.