sykes Posted October 11, 2005 Posted October 11, 2005 Code for formatting a Social Security Number! (Thanks again Valik): Local $sOriginal = "123121234" Local $sFormatted = StringRegExpReplace($sOriginal, "(.{3}){1}(..{1})", "\1-\2-\3") MsgBox(0, "", $sFormatted) We have enough youth. How about a fountain of SMART?
jefhal Posted October 11, 2005 Author Posted October 11, 2005 Code for formatting a Social Security Number! (Thanks again Valik):What a concept! Learning by example (extrapolation)... Let's hope these examples are added to the next help file? ...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format
RobertH Posted April 7, 2010 Posted April 7, 2010 Sorry to reopen a closed conversation but I did a search to see if I could find some code to format a phone number and I was presented with this conversation. I tried to implement Jefhal's code to format a 10 digit phone number but it only displays "456-7890-" and not "123-456-7890". I can't figure out how to get it to display correctly. I have tried entering a zero in the second line but it only produces the whole phone number followed by a dash then the last four followed by a dash. Here is what I tried Local $sFormatted = StringRegExpReplace($sOriginal, "(.{3}){2}(....{1})", "\0-\2-\3") Can someone help me figure this out? I have read the help file but it doesn't make sense to me. It would be helpful to have an example that I can play with and learn from.
RobertH Posted April 7, 2010 Posted April 7, 2010 Sorry to reopen a closed conversation but I did a search to see if I could find some code to format a phone number and I was presented with this conversation. I tried to implement Jefhal's code to format a 10 digit phone number but it only displays "456-7890-" and not "123-456-7890". I can't figure out how to get it to display correctly. I have tried entering a zero in the second line but it only produces the whole phone number followed by a dash then the last four followed by a dash. Here is what I tried Local $sFormatted = StringRegExpReplace($sOriginal, "(.{3}){2}(....{1})", "\0-\2-\3") Can someone help me figure this out? I have read the help file but it doesn't make sense to me. It would be helpful to have an example that I can play with and learn from. I think I figured it out. This works for formatting a phone number. Local $sOriginal = "1234567890" Local $sFormatted = StringRegExpReplace($sOriginal, "(.{3}){1}(...{1})", "\1-\2-\3") MsgBox(0, "", $sFormatted)
Spiff59 Posted April 7, 2010 Posted April 7, 2010 (edited) I think I figured it out. This works for formatting a phone number. Local $sOriginal = "1234567890" Local $sFormatted = StringRegExpReplace($sOriginal, "(.{3}){1}(...{1})", "\1-\2-\3") MsgBox(0, "", $sFormatted) Either of these seems sufficient: Local $sFormatted = StringRegExpReplace($sOriginal, "(...)(...)", "\1-\2-") Local $sFormatted = StringRegExpReplace($sOriginal, "(.{3})(.{3})", "\1-\2-") I like this for the original OP's request (Mac address): Local $sFormatted = StringRegExpReplace($sOriginal, "(..)(?!$)", "\0-") Edit: Ok, I've just about totally confused myself with regular expressions (again), so am not sure this is the most direct way, but this works with 7 or 10-digit phone numbers: Local $sFormatted = StringRegExpReplace($sOriginal, "(...)?((....)$|(...))", "\1-\2") Edited April 7, 2010 by Spiff59
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now