deleyd
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:
One thing is my project is Visual Basic VB.net and this is a C# package.
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>
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");
One thing is my project is Visual Basic VB.net and this is a C# package.
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
Which test are you looking at (i.e. the stuff you mentioned in your original post)?
ASKER
I found it. (Yet still not sure how to use it.) Tests are at:
https://bitbucket.org/pmez ard/libpho nenumber-c sharp/src/ f5236354a3 79/csharp/ PhoneNumbe rs.Test?at =csharp
I can do:
But still not sure what I can do. I can almost do:
https://bitbucket.org/pmez
I can do:
Imports PhoneNumbers
with no complaints.But still not sure what I can do. I can almost do:
Dim formatter As AsYouTypeFormatter = phoneUtil.GetAsYouTypeFormatter("ZZ")
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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)
I guess as with much of great code there is little documentation making the code much less useable.
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.
I found some of the solution myself, however comments by others were helpful in jogging my imagination as I sought a creative solution.
As to your issue, are you importing the namespace at the top of your code file?