Results 1 to 4 of 4

Thread: Format function doesn't work in ASP.NET?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Posts
    416

    Format function doesn't work in ASP.NET?

    Ok... I have a string that contains "1" ... I want to format it so that it will hold "00000001"

    So I just do...

    s1 = "1"
    s2 = Format(s1, "00000000")

    s2 now equals "00000000" ... when it should be "00000001"

    This works in regular VB, but not ASP.NET .... WHY?!

  2. #2
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    Well, for starters, ASP.NET <> VB.

    Try this:
    VB Code:
    1. Dim s1 As String = "1"
    2. Dim s2 As String = s1.PadLeft(8, "0")

  3. #3
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    I realize this is way after the fact, but the reason this didn't evaulate correctly is due to namespace operations.

    First, ASP.NET, when Language = VB IS VB.Net.

    The reason this doesn't work right off is that the namespace resolution engine does not know which FORMAT to use and uses the wrong one.

    Instead of
    s2 = Format(s1, "00000000")
    use
    s2 = String.Format(s1, "00000000")

    Since the Format object you were looking for is the Format object of the String class.
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  4. #4
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    While I'm at it, I might as well point out that the way you are doing it will be deprecated some time in the future. (Microsoft never gives estimates)

    They now recommend:

    s2 = Double.Parse(s1).ToString("00000000")
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width