Link to home
Start Free TrialLog in
Avatar of deleyd
deleydFlag for United States of America

asked on

Trying to use libphonenumber-csharp NuGet package

I would like to format a phone number. The program could be run anywhere in the world, so should format phone number for local standards.

I found the C# port of Google's The C# version is at

I got NuGet installed, and did:

PM> Install-Package libphonenumber-csharp

It added a "packages.config" file to my project:
<?xml version="1.0" encoding="utf-8"?>
  <package id="libphonenumber-csharp" version="" targetFramework="net40-Client" />

Open in new window

and that's as far as I've got. From here I'm not sure how to access the functionality of the package. The tests in the source code say I should be able to do something like:
            PhoneNumberInfo phoneInfo = null;

            phoneInfo = LibPhoneNumber.DoFormatAndFindRegion(@"+41 (0)31 388 10 10");

Open in new window

One thing is my project is Visual Basic and this is a C# package.
Avatar of kaufmed
Flag of United States of America image

One thing is my project is Visual Basic and this is a C# package.
That doesn't matter. The project could be written in IronPython, and you would still be able to use it (provided the version of .NET in use is compatible). When .NET languages are compiled to assemblies, such assemblies contain intermediate language (known as MSIL--Microsoft Intermediate Language). Any .NET language is compiled to this. This allows the .NET runtime to run code that was written in any .NET language.

As to your issue, are you importing the namespace at the top of your code file?
Avatar of deleyd


I'm not sure what the namespace is I need to import. I tried various Import statements but Visual Studio complained about all of them. I tried:
Imports libphonenumber-csharp
Imports libphonenumber.csharp
Imports libphonenumber
Imports GlauxSoft.Phone.NumberUtil

Open in new window

Which test are you looking at (i.e. the stuff you mentioned in your original post)?
Avatar of deleyd


I found it. (Yet still not sure how to use it.) Tests are at:

I can do:
Imports PhoneNumbers

Open in new window

with no complaints.

But still not sure what I can do. I can almost do:
Dim formatter As AsYouTypeFormatter = phoneUtil.GetAsYouTypeFormatter("ZZ")

Open in new window

but Visual Studio complains it doesn't know what phoneUtil is. I'm trying to find an example of where that gets instantiated.
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of deleyd


I've had some success with the following code:
        Dim phoneUtil As PhoneNumberUtil = PhoneNumberUtil.GetInstance()
        Dim formatter As AsYouTypeFormatter = phoneUtil.GetAsYouTypeFormatter("US")
        Dim x As String
        'x = formatter.InputDigit("1"c)
        x = formatter.InputDigit("8"c)
        x = formatter.InputDigit("0"c)
        x = formatter.InputDigit("5"c)
        x = formatter.InputDigit("5"c)
        x = formatter.InputDigit("5"c)
        x = formatter.InputDigit("5"c)
        x = formatter.InputDigit("1"c)
        x = formatter.InputDigit("2"c)
        x = formatter.InputDigit("3"c)
        x = formatter.InputDigit("4"c)

Open in new window

I guess as with much of great code there is little documentation making the code much less useable.
Avatar of deleyd


(I'm having trouble closing this question. Website technical issues.)

I found some of the solution myself, however comments by others were helpful in jogging my imagination as I sought a creative solution.