how to extract data from AD with VBS, and modify the output by adding spaces, brackets and a dash


i need a sub routine that will read a telephone number from AD and then modify the number by inserting spaces, brackets and dashes into the final output.
the final input is then used in our signature script.
script is working perfectly well i just need to make this small modification.

i think it would fairly simple to do but my vbs skills arent there yet... so im not really sure where to start and what commands i should be looking at.

so to sum things up

as you can see from this image, the phone number comes in the format +xxxxxxxxxxxx
Phone Number
i need this sub routine to modify the number into the following format

+xx (xx) xxxx-xxxx

once the sub has created this into a final output it will then be called by another Sub and entered into the section of the script that creates the signature.

the line in the script that will call on this is

SigFileStream.WriteLine " T " + g_objldapuser.telephoneNumber + " | " +" M " + + " | " + " F +xx xxxxxxxx "

Open in new window

id like to replace g_objldapuser.telephoneNumber with the final formatted output from the sub routine so it looks something like this.

SigFileStream.WriteLine " T " + sFormattedPhone + " | " +" M " + + " | " + " F +xx xxxxxxxx

Open in new window

i hope this makes sense...  does anybody have a script that does something like this?
or if you could guide me in the right direction that would be great..

please let me know if you need any more info.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi, this should work for you.



sFormattedPhone = g_objldapuser.telephoneNumber
sFormattedPhone = Left(sFormattedPhone, 3) & " (" & Mid(sFormattedPhone, 4, 2) & ") " & Mid(sFormattedPhone, 6, 4) & "-" & Right(sFormattedPhone, 4)
SigFileStream.WriteLine " T " + sFormattedPhone + " | " +" M " + + " | " + " F +xx xxxxxxxx "

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BakerSydAuthor Commented:
fantastic... does exactly what i need

thanks Rob!
No problem. You had already done the legwork so my part was easy ;-)

Thanks for the grade.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.