Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

right fomat for phone # 3

Status
Not open for further replies.

maggielady

Technical User
Jan 3, 2003
60
US
if i have a field in a db called famphone and the phone # is in this format: (123 2342345 and I want it to be like this (123) 234-2345 what would the replace statment be? I've been trying for awhile and can't quite get it exactly right. Thanks for any help
 
maggielady

In your textbox inputmaks put :
(999)-999-9999

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
not sure what you mean mgagon, I'm new using foxpro 6???
 
(123 2342345

If the phone number is actually in the format above you could say something like:


REPLACE phonenum with LEFT(phonenum, 4) + ') ' + SUBSTR(phonenum, 6, 3) + '-' + RIGHT(phonenum, 4)

Jim
 
maggielady

not sure what you mean mgagon, I'm new using foxpro 6???

Sorry, I misread the question. Jim has the answer.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Assuming the field is at least 14 characters wide, you could "fix" them all with:
Code:
REPLACE ALL famphone.phonenum WITH TRANSFORM(;
 CHRTRAN(famphone.phonenum, CHRTRAN(famphone.phonenum, "0123456789", ""), "") ;
 , "@R (XXX) XXX-XXXX")
Note: The "first" part CHRTRAN(...CHRTRAN(...)) will strip out anything but the digits, and the second part TRANSFORM(..., "@R (XXX) XXX-XXXX") will put it back into your requested format.

Rick
 
maggielady,

Assuming the table always has complete 10-digit numbers, you can try this code:
Code:
do while !eof()
  cDigitsOnly = chrtran(FAMPHONE,chrtran(FAMPHONE,"0123456789",""),"")
  cNewFormat = "("+left(cDigitsOnly,3)+") "+ ;
     subs(cDigitsOnly,4,3)+"-"+ ;
     right(cDigitsOnly,4)
  replace FAMPHONE with cNewFormat
  skip
endd
Make sure the FAMPHONE field length is at least 14 characters to prevent truncated result after reformatting.

HTH

Medic
 
Hey Rick,

I never saw your post. Looks like we have the same idea. And your solution is definitely simpler.

Medic
 
Medic,
I'd simply suggest that a) Great minds think alike :), b) I type faster than you do!

Rick
 
Rick,

"... b) I type faster than you do!"

I would say "Brilliant mind makes the hands faster." [thumbsup2]

Medic





 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top