×

Loading...

Topic

This topic has been archived. It cannot be replied.
  • 工作学习 / IT技术讨论 / A Small VB Question (post again)
    I have bunch of telephone numbers like this
    1-416-123*-887-*9877@888-99908
    one thing I'm sure is before 416- is area code and
    after the final dash, it's extention.

    it's transfered from a legacy system and I got only a
    txt file contians all these numbers.

    what I want to do is to keep area code and extention,
    replace last "-" with "ext", remove all non-numeric
    characters in the middle,any easy way in VB to solve it?
    • 1,regular express, (best) 2, or a) find how many\" -\"; b) deal with it (break and combine it).
      • figure it out. Thank you. And thanks everyone who contributes his/her time
        Set regEx = New RegExp
        sVariable = "416-1@rfr4535ef34hb-653yuyue904537 73--39 hbhg324-789"
        regEx.Global = True
        regEx.Pattern = "^(\d+-)(.*)(-\d+)$"
        Set oMatches = regEx.Execute(sVariable)
        regEx.Pattern = "\D"
        sNewVariable = oMatches(0).SubMatches(0) & regEx.Replace(oMatches(0).SubMatches(1), "") & Replace(oMatches(0).SubMatches(2), "-", "ext")
        • 7 lines code, no loop. great
        • actually, it is an interview question, hope my answer helps when you guys meet thi squestion again in your interview
    • 1,regular express, (best) 2, or a) find how many\" -\"; b) deal with it (break and combine it).