?
Solved

telephone number manipulation

Posted on 2011-09-06
10
Medium Priority
?
415 Views
Last Modified: 2013-12-18
Hi

How can I manipulate this string    -800-238-7828

to end up with this string      (800) 238 7828

Thanks

Mike  
0
Comment
Question by:BulldogMike
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 2

Assisted Solution

by:gingerdeb
gingerdeb earned 400 total points
ID: 36492080
Try:

Dim ictr as Integer
Dim origString as String
Dim tmpString as String

origString = "-800-238-7828"

ictr = Instr(origString, "-")
While ictr > 0
     If ictr = 1 Then
          tmpString = "(" + Mid$(origString, ictr+1)
     Elseif ictr = 5 Then
          tmpString = Left$(tmpString, ictr-1) + ") " + Mid$(tmpString, ictr+1)
     Else
          tmpString = Left$(tmpString, ictr-1) + " " + Mid$(tmpString, ictr+1)
     End if
     ictr = Instr(tmpString, "-")
Wend
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 36492353
Split can be your friend...

x= Split(orig, "-")
conv= "(" + x(1) + ") " + x(2) + " " + x(3)

If you want to accept multiple input formats, have a look at Regex:
http://www.regular-expressions.info/vb.html

If you want it in formula language:

x:= @Trim(@Split(orig; "-"));
conv:= "(" + x[1] + ") " + x[2] + " " + x[3];
0
 
LVL 11

Assisted Solution

by:larsberntrop
larsberntrop earned 400 total points
ID: 36493939
hey sjef:  You forgot fulltrim in the script example:

Function FormatPhone(strPhoneMin$) As String
   Dim x As Variant
   x = Fulltrim(Split(strPhoneMin, "-"))
   If Ubound(x) > 1 Then
      FormatPhone = "(" & x(0) & ") " & x(1) & " " & x(2)
   Else
      FormatPhone = Join(x)
   Endif
End Function

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 36493973
Yes, I could have added it, but it's up to Mike to fit the code in. Just mentioned some options...
0
 

Author Comment

by:BulldogMike
ID: 36502419
Hi

Maybe I shpuld have shared this with you before - could you indicate how to work you solutions into these statements: the TEM_CBK_PHN_NB and TEM_FAX_NB components are the telephone and fax numbers repectively

@ProperCase(PHP_ADR_LN1) + ",  " + @ProperCase(LOC_CD) +
@NewLine  + @ProperCase(PHP_ADR_LN2) +
@NewLine + TEM_CBK_PHN_NB +
@NewLine +  TEM_FAX_NB + "  " + "Fax"

Thank you for your help.  it looks like you all will get points on this one

Mike
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 36502741
As I expected: formula :-)

Instructions?
You take the keyboard, you type the I, then the .... C'mon man, think and try by yourself first!

Hint --- add these lines at least once:

tel:= @Trim(@Split(TEM_CBK_PHN_NB; "-"));
telf:= "(" + tel[1] + ") " + tel[2] + " " + tel[3];

and use telf instead of TEM_CBK_PHN_NB
0
 

Author Comment

by:BulldogMike
ID: 36502856
Sorry Seif

I am a healthcare professional and a novice programmer at best - I learn to program by reading books and doing it on the job.  This is basic stuff for you but it's Greek to me since I lack formal IT training

Thanks

Mike
0
 

Author Comment

by:BulldogMike
ID: 36503011
Apparently @ SPLIT is not an available function in Notes 5.0

Should I use @ left or @middle to parse the data as an alternative?

Thank You

Mike
0
 
LVL 46

Accepted Solution

by:
Sjef Bosman earned 1200 total points
ID: 36503344
Oh shoot, my bad... :$  And Notes R5, eh? The code will indeed be different then:

tel:= @Trim(@Explode(TEM_CBK_PHN_NB; "-"));
telf:= "(" + @Subset(@Subset(tel; 2);-1) + ") " + @Subset(@Subset(tel; 3);-1) + " " + @Subset(@Subset(tel; 4);-1);

0
 

Author Closing Comment

by:BulldogMike
ID: 36522386
As always these experts are very helpful.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem "Can you help me recover my changes?  I double-clicked the attachment, made changes, and then hit Save before closing it.  But when I try to re-open it, my changes are missing!"    Solution This solution opens the Outlook Secure Temp Fold…
Article by: Rob
Notes 8.5 Archiving Steps and Tips This article covers setting up a Notes archive, and helps understand some of the menu choices making setting up and maintaining a Notes archive file easier.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month12 days, 19 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question