Results 1 to 4 of 4

Thread: Formatting String ? [*RESOLVED*]

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2003
    Posts
    17

    Formatting String ? [*RESOLVED*]

    Hi !

    How can format a string in the Social Security Format which is
    999-99-9999

    I have to show a SSN in the above format in a resulting ASP page, which is entered by a user.

    Right now I use the follwing code in my .asp page

    Code:
    tempSSN = request.querystring("SSN")
    <%
    response.write(tempSsn)
    %>
    and SSN is displayed as 999999999.


    Any help would be appreciated.

    Thanks
    Nandu
    Last edited by getnandu; Nov 12th, 2003 at 08:35 AM.

  2. #2
    Fanatic Member RealisticGraphics's Avatar
    Join Date
    Jul 1999
    Location
    Arkansas
    Posts
    655
    I don't believe VBScript has a Format function... But you could do it this way:

    VB Code:
    1. SSN = "999999999"
    2. fSSN = mid(SSN, 1, 3) & "-" & mid(SSN, 4, 2) & "-" & mid(SSN, 7, 4)
    3.  
    4. response.write(fSSN)
    www.RealisticGraphics.net

    Running VS.Net Enterprise & VB 6

    Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML

    MSN Messenger: kmsheff

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Here's how I do it in PHP (which is about what RG posted, only that the first line pads a too-short SSN with 0)
    Code:
    function format_ssn($ssn)
    {
    	$ssnstring = sprintf("%010s", $ssn);
    	$ssnstring = substr($ssnstring, 0, 4)."-".substr($ssnstring, 4, 2)."-".
    		substr($ssnstring, 6, 2)."-".substr($ssnstring, 8, 2);
    	return $ssnstring;
    }
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Nov 2003
    Posts
    17
    It works like a charm.

    Thanks a lot guys.................


    Nandu

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