Format a string

Results 1 to 2 of 2

Thread: Format a string

  1. #1
    Join Date
    Dec 1969

    Default Format a string

    I am getting phone numbers from database as string and I need to format them when I display them to users like this 888-888-8888.<BR>How could I do this with asp.<BR>Thanks <BR>VInay Bansal

  2. #2
    Cable Guest

    Default RE: Format a string

    This will only work if the phone numbers are unformatted and are in the format of 5555555555 ten digits with no hyphens and so forth:<BR><BR>Function Fix_Phone(s_Phone)<BR>Dim s_Temp <BR>Dim c_Temp <BR>Dim i_pos <BR><BR>If Trim("" & s_Phone) &#060;&#062; "" Then<BR> i_pos = 1<BR> s_Temp = ""<BR> c_Temp = ""<BR> Do While Len(s_Phone) &#062;= i_pos<BR> c_Temp = Mid$(s_Phone, i_pos, 1) &#039Get next character in string<BR> <BR> If i_pos = 4 Or i_pos = 7 Then<BR> s_Temp = s_Temp & "-" &#039Add a hyphen<BR> End If<BR> <BR> If i_pos &#060;= Len(s_Phone) Then<BR> s_Temp = s_Temp & c_Temp &#039Add the character to the temp string<BR> End If<BR> <BR> i_pos = i_pos + 1<BR> Loop<BR> Fix_Phone = s_Temp<BR>Else<BR> Fix_Phone = ""<BR>End If<BR>End Function

Posting Permissions

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