Hi there,
I have used the below code to format an int value to a mask text box in C#.
How can I avoid replacing the zeros in between the the numbers other than the zero’s in the front of the number.
How can I do this, as an example
00000234 will be displayed as 234
How can I display 00230234 as 230234, for the moment it displays as 23 234.
How can I avoid this situation

thanxxxxxx

String amt = reader[11].ToString();

                if ((amt == "0.00") || (String.IsNullOrEmpty(amt)))
                    mtxtAmt.Text = "";
                else
                {
                    decimal d;
                    decimal.TryParse(amt, out d);
                    String Val1 = d.ToString("$00000000000000.00");
                    int index1 = Val1.IndexOf(".");
                    String val1 = Val1.Substring(0, index1);
                    
                    String FValue1 = val1.Replace("0", " ");
                    String LValue1 = Val1.Substring(index1, (Val1.Length - index1));
                    mtxtAmt.Text = FValue1 + LValue1;
}

What a very clumsy way to do padding.
There are methods to add padding to a string.
Take a look at this.

string amt = "    123.56   ";

            string value = string.Empty;
            decimal dec;
            if (decimal.TryParse(amt.Trim(), out dec))
            {
                value = (dec * 100).ToString("F0");
                value = value.PadLeft(16); //<-- not sure of field width
            }
            mtxtAmt.Text = value;

Seriously? This again?
Have you tried any of the suggestions from this post, or this one...maybe this one?

Please don't flood the boards with the same question. If you absolutely must ask for further advise then psot in your original thread, it will be refreshed and bumped to the top of the forum to get any attention it needs. Posting hte same question over and over just makes more typing for you and spreads the answers out making it harder for others to find them.

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.