Format String variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • danishce
    New Member
    • Apr 2007
    • 31

    #1

    Format String variable

    Hello:
    I want to format fixed length string using vb.net. If the size of string is less than field size then it should filled with zero.
    ex:i want to format fixed length 10 digit amount field which is input by the user.if the user fills only 6 digits then the data will be left justified and on the right side remaining 4 digits it filled with zeroes.
    1)Enter Amount="500100"
    formatted string="5001000 000"
    2)Enter Amount="500"
    formatted string="5000000 000"
    please guide me urgently?
    Thanks
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    One way would to create a loop where string.length > 10 string += 0. This is not the exact code bot may get you started.

    Comment

    • jku
      New Member
      • May 2007
      • 2

      #3
      Originally posted by danishce
      Hello:
      I want to format fixed length string using vb.net. If the size of string is less than field size then it should filled with zero.
      ex:i want to format fixed length 10 digit amount field which is input by the user.if the user fills only 6 digits then the data will be left justified and on the right side remaining 4 digits it filled with zeroes.
      1)Enter Amount="500100"
      formatted string="5001000 000"
      2)Enter Amount="500"
      formatted string="5000000 000"
      please guide me urgently?
      Thanks
      I am not familiar with vb.net but the idea will be the same as the following solution in C#

      string sInput = "5000"
      string sResult = sInput.PadRight (10, '0');

      The above should return "5000000000 " for sResult

      Comment

      Working...