By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,384 Members | 671 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,384 IT Pros & Developers. It's quick & easy.

reverse string matching

100+
P: 153
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.
Jan 27 '09 #1
Share this Question
Share on Google+
7 Replies


100+
P: 179
@akshaycjoshi
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:

Expand|Select|Wrap|Line Numbers
  1. public void CheckCost(string number)
  2. {
  3. string match1 = @"^9826";
  4.    if(Regex.IsMatch(number, match1)
  5.    {
  6.       // Do Something if the number started 9826
  7.    }
  8.    else if (Regex.IsMatch(number // another match in here
  9. }
  10.  
Jan 27 '09 #2

100+
P: 153
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
'
Jan 27 '09 #3

shweta123
Expert 100+
P: 692
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.
Jan 27 '09 #4

100+
P: 179
@akshaycjoshi
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".
Jan 27 '09 #5

100+
P: 153
@shweta123
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.
Jan 28 '09 #6

100+
P: 344
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.
Jan 29 '09 #7

shweta123
Expert 100+
P: 692
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.
Feb 2 '09 #8

Post your reply

Sign in to post your reply or Sign up for a free account.