Consider the following function

# Thread: Consider the following function

1. Senior Member
Join Date
Dec 1969
Posts
1,686

## Consider the following function

Function FormatPhoneNumber(strPhoneNumber)<BR>strPhoneNumbe r = trim(strPhoneNumber)<BR><BR>&#039; for now, I&#039;m only checking for dashes - leaving parens out<BR>for i = 1 to len(strPhoneNumber)<BR> strCurrentNumber = mid(strPhoneNumber, i, 1)<BR> if not isNumeric(strCurrentNumber) then<BR> strPhoneNumber = replace(strPhoneNumber, strCurrentNumber, "")<BR> call FormatPhoneNumber(strPhoneNumber)<BR> else<BR> FormatPhoneNumber = strPhoneNumber<BR> end if<BR>next<BR>End function<BR><BR>Response.Write FormatPhoneNumber("800-555-1212")<BR>Response.end<BR><BR><BR>I chose to use a recursive function to get more than 1 dash out. Is there a better technique than this that anyone can offer?<BR><BR>Thanks

2. Senior Member
Join Date
Dec 1969
Posts
1,686

## Also I just noticed

it should work with parens as well. So please ignore the first comment.

3. Senior Member
Join Date
Dec 1969
Posts
2,885

## Replace?!?

Why not response.write(replace("800-555-1212", "-", "")) ???

4. Senior Member
Join Date
Dec 1969
Posts
1,686

## Because?!?

I dont know if there will be a dash, or parens, a G, etc, in it... seemed to make more sense writing a function for it to check ANY non numeric, as opposed to just one thing

5. Senior Member
Join Date
Dec 1969
Posts
3,921

## It is fine but you don't need recursion

you could accomplish the same without it.

6. Senior Member
Join Date
Dec 1969
Posts
1,686

## heh - lookitdat

7. Senior Member
Join Date
Dec 1969
Posts
2,885

## That what RegExp is for

option explicit<BR><BR>dim strPhone<BR>dim objRE<BR><BR><BR>strPhone = "(""800-123-4567"")"<BR><BR>set objRE = new RegExp<BR><BR>objRE.Global = true<BR>objRE.IgnoreCase = true<BR>objRE.Pattern = "[^0-9]"<BR><BR>strPhone = objRE.Replace(strPhone, "")<BR>Response.Write(strPhone)<BR><BR><BR>set objRE = nothing

8. Senior Member
Join Date
Dec 1969
Posts
1,686

## I know, but

why use an object when the overhead of calling a function is far less?

9. Senior Member
Join Date
Dec 1969
Posts
2,885

## Whaaaat?

I guarantee that my code will run faster than yours.

10. Senior Member
Join Date
Dec 1969
Posts
1,686

## i dont want a guarantee

and its not a competition - but why do you think it will run faster? i&#039;m just looking for a more efficient way - the string is only at most 13 characters long, so running MID on it shouldnt make it chug... versus the overhead of an object?<BR><BR>

#### Posting Permissions

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