reverse string matching

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • akshaycjoshi
    New Member
    • Jan 2007
    • 153

    reverse string matching

    I have got one database representing the different telephone numbers' masks.





    The field masks shows the diff types of telephone no(S) and the corresponding cost and no of seconds in one unit.

    when a telephone no arrives at serial port after the end of call i have to get the cost.
    The problem is
    How would i match a number like '9826512030' to the database and find the cost of it.
    match clause in Sql works like this :
    where ... like '98265%'
    Here it is diff ! i have to find the mask correspondign to the number.
  • IanWright
    New Member
    • Jan 2008
    • 179

    #2
    Originally posted by akshaycjoshi
    I have got one database representing the different telephone numbers' masks.





    The field masks shows the diff types of telephone no(S) and the corresponding cost and no of seconds in one unit.

    when a telephone no arrives at serial port after the end of call i have to get the cost.
    The problem is
    How would i match a number like '9826512030' to the database and find the cost of it.
    match clause in Sql works like this :
    where ... like '98265%'
    Here it is diff ! i have to find the mask correspondign to the number.
    A fairly simple way would be to have set of Regex statements, and see which one matches... A useful reference site is : http://regexlib.com/CheatSheet.aspx .

    In case you haven't used Regex before then you would do something like:

    Code:
    public void CheckCost(string number)
    {
    string match1 = @"^9826";
       if(Regex.IsMatch(number, match1)
       {
          // Do Something if the number started 9826
       }
       else if (Regex.IsMatch(number // another match in here
    }

    Comment

    • akshaycjoshi
      New Member
      • Jan 2007
      • 153

      #3
      ty IanWright.

      Ok a simple where clause did the trick.
      <number> like(mask)

      Ex.
      '9826510320 like (mask)

      I have now one more problem.

      How would i determine ambiguity in the masks.
      for ex. a number 982651088 would fit in both
      "98%" and "982%"

      I guess a cartesion product of mask X mask will do the thing
      from t_mask one , t_mask two where
      one.mask like(two.mask)
      But i am missing the syntax .

      Can anyone help me out ?

      Thanks
      '

      Comment

      • shweta123
        Recognized Expert Contributor
        • Nov 2006
        • 692

        #4
        Hi,

        Please tell that why are you taking the masks? Do the mask field in the database table are used for matching the country code or state code in each telephone no.In that case every telephone no will match only one mask.

        Comment

        • IanWright
          New Member
          • Jan 2008
          • 179

          #5
          Originally posted by akshaycjoshi
          ty IanWright.

          Ok a simple where clause did the trick.
          <number> like(mask)

          Ex.
          '9826510320 like (mask)

          I have now one more problem.

          How would i determine ambiguity in the masks.
          for ex. a number 982651088 would fit in both
          "98%" and "982%"

          I guess a cartesion product of mask X mask will do the thing
          from t_mask one , t_mask two where
          one.mask like(two.mask)
          But i am missing the syntax .

          Can anyone help me out ?

          Thanks
          '
          Honestly I'd still recommend going down the Regex route, is incredibly powerful and not too difficult to get the basics.

          Regardless of which way you doing it, look for most specific first, if that fails, then go for the more general case, just like catching exceptions.

          See if it matches "982", if it doesn't, check "98".

          Comment

          • akshaycjoshi
            New Member
            • Jan 2007
            • 153

            #6
            Originally posted by shweta123
            Hi,

            Please tell that why are you taking the masks? Do the mask field in the database table are used for matching the country code or state code in each telephone no.In that case every telephone no will match only one mask.
            Hi,
            The output string from the PBX cantains the number dialed by the extension.
            It does not necessarily cantain the country code.
            It cantains whatever the extension user dials.
            Ex-639167197020 (here the extension user is calling other country)
            09826546512 (An STD mobile no. , since it starts from 09)
            98265987336 ( A local mobile no)

            Masks are used to get info about the dialed number's cost.
            SOmetimes the PBX owner has free STD mobile call facility,in this case the owner can have this mask
            "09%" duration= whatever, cost=0 Rs.

            Can u find ou any problem in his method.
            If yes please tell me so that i can think of the other way.

            I need to find out clashes like I explained above when 2 masks match a number .
            Clashes can be there cox the -PBX owner maybe a layman.

            Comment

            • Bassem
              Contributor
              • Dec 2008
              • 344

              #7
              Hi,
              If the length of each number-category is fixed,
              ie 10 for Mobile, 12 for other country ...etc. You may use underscores instead of each number, and for its corresponding position.
              for example:
              09826546512 use LIKE '098________' // 098 then 8 underscores
              98265987336 use LIKE '982________' // 982 then 8 underscores
              and not number will match two masks.

              Comment

              • shweta123
                Recognized Expert Contributor
                • Nov 2006
                • 692

                #8
                Hi,

                One way is to calculate the mask for the given telephone number in the .Net code. You can use the substring function in order to get mask for that number.

                Then you can write the sql query to get the record from database table which is having the calculated mask.

                e.g.

                Sql = "Select * from t_mask where mask like '" & strmask & "'"

                Here strmask is the mask you have get by using substring function.

                Comment

                Working...