|
Get the IP address. Translate the address to a country:
IP Location Finder - Geolocation[^]
Append the "country code" to the input.
(Whether this happens client or server-side depends on the view states).
|
|
|
|
|
Dears,
I have a table that contain country name + phone code and another table of called phone number.
what is the way to know the phone calls destinations using the first table that contains the codes and country name
example
table 1: 961 | Lebanon
table 2: 9613211311 => Lebnon
|
|
|
|
|
SELECT table1.Country FROM table1 JOIN table2 ON table1.Code = MID(table2.PhoneNumber, 1, 3) WHERE table2.PhoneNumber = '9613211311';
I may have misused the MID function, but you get the point.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
thanks, the codes are variable, they may be 1 char such as USA code is 1 and reaches 9 chars such as India code,
the dialed numbers in the other table are to many countries
|
|
|
|
|
So something like this:
SELECT TOP 1
Country
FROM
CountryCodes
WHERE
@PhoneNumber Like Code + '%'
ORDER BY
Len(Code) DESC
;
That will give you the country for a single phone number passed in as a parameter. If there are multiple matching country codes, it will return the country for the longest matching code.
If you want the country for multiple phone numbers, try:
WITH cteCodes As
(
SELECT
CountryCodes.Country,
PhoneNumbers.PhoneNumber,
ROW_NUMBER() OVER (PARTITION BY PhoneNumbers.PhoneNumber ORDER BY Len(CountryCodes.Code) DESC) As RN
FROM
CountryCodes
INNER JOIN PhoneNumbers
ON PhoneNumbers.PhoneNumber Like CountryCodes.Code + '%'
)
SELECT
Country,
PhoneNumber
FROM
cteCodes
WHERE
RN = 1
;
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Maybe an INNER JOIN ON a LIKE ? Which database system?
|
|
|
|
|
|
Next time, please post a database question in the database forum
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
|
So you want to do this matching in your C# app and not with SQL?
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
|
(Why didn't you tell Richard Andrew?)
Then what type are the tables you have there? System.Data.DataTable ?
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Be sure that you validate that the numbers in the second table are in the form that you expect.
|
|
|
|
|
Disclaimer: This is not a question asking for help with programming, more of a short survey.
Now that we have string interpolation built into C# 6, do you still see a use for String.Format or for some custom String.Format-replacement or prefer one or the other to the inbuilt interpolation? (And if so, why?)
Do you have a project where fast string formatting is critical?
///
I wrote a String.Format-replacement before C# 6 came out and I've started writing an article on that. Even if there might be no actual need for it any more, it still makes a really good example for using compiled expressions (which is why my solution is blazing fast for the second and following uses of the same format string). Getting some more opinions on this might be useful for the introduction / the way I'll present it.
cheers,
Sascha
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
For a lot of people, upgrading to the latest version of C# will be a prohibited move due to workspace constraints. I would imagine that any display of alternatives would be a welcome addition for them.
This space for rent
|
|
|
|
|
Pete O'Hanlon wrote: For a lot of people, upgrading to the latest version of C# will be a prohibited move due to workspace constraints. Thank you for that point. Being a sole developer selling my own programs in binary only I don't have to think about those issues. I expected the .NET-version would be a workspace constraint for people but didn't expect the C#-version to be one as well. VS licensing issues I guess.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
It's more to do with corporations having .NET version upgrades in place. For instance, while .NET 4.5 builds on top of .NET 4, there were many breaking changes internally where people had put fixes in place for bugs in 4 that were done away with in 4.5, so things just didn't work the same. When a company has to think about 10K internal users, that's a lot of planning and upgrade that they have to do.
This space for rent
|
|
|
|
|
Doesn't the fact that string interpolation is only dependent on the version of the C# compiler make considerations on the compatibility of .NET versions obsolete in this case?
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Unfortunately - for most corporations, they won't upgrade the compiler independently of the framework. They will upgrade the compiler when they install VS 2015.
This space for rent
|
|
|
|
|
I see. Thank you, Pete!
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
I'm still using String.Format method when the string is in a resource file.
For example, imagine you have this string resource:
MyStringResource = "A problem occured in {0}."
You then cannot use the new C# 6 string interpolation, and have to resort to the good old:
string location = "an undefined place";
string message = string.Format(Resources.MyStringResource, location);
Other than that, I try to use the string interpolation where I can.
Regards.
I never finish anyth
|
|
|
|
|
Also a good point, thank you!
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Sascha Lefèvre wrote: interpolation built into C# 6,
I have no plans to use either. String.Format will continue to be my weapon of choice for a good long while.
The ability to compile against older versions will often outweigh the "shiny and new".
Don't use any new feature unless and until it provides a real benefit.
Consider, also, what if you write code that must compile under new and old versions? Will you write it both ways with conditional compilation? Make a branch in your version control and have to maintain two versions? Isn't it simpler to write it only the "old" way and reduce maintenance?
On the other hand, I have an Extension Method:
public static string
Format
(
this string Format
,
System.Collections.IList Parameter
)
(By the by, Extension Methods are about the newest C# feature I use, even though I feel they were implemented wrong.)
|
|
|
|
|
PIEBALDconsult wrote: The ability to compile against older versions You can use string interpolation with older .NET versions, you just have to use the C# 6 compiler. Or am I missing your point?
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|