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 https://code.google.com/p/libphonenumber/. The C# version is at https://bitbucket.org/pmezard/libphonenumber-csharp

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"?>
<packages>
  <package id="libphonenumber-csharp" version="4.10.0.62" targetFramework="net40-Client" />
</packages>

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 VB.net and this is a C# package.
Avatar of kaufmed
kaufmed
Flag of United States of America image

One thing is my project is Visual Basic VB.net 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

ASKER

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

ASKER

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

https://bitbucket.org/pmezard/libphonenumber-csharp/src/f5236354a379/csharp/PhoneNumbers.Test?at=csharp

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.
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
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

ASKER

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

ASKER

(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.