PhoneNumberFormatter.TryCreate(String, PhoneNumberFormatter) Method

Definition

Attempts to create a PhoneNumberFormatter for a given region code, and doesn't throw on failure.

public:
 static void TryCreate(Platform::String ^ regionCode, [Out] PhoneNumberFormatter ^ & phoneNumber);
 static void TryCreate(winrt::hstring const& regionCode, [Out] PhoneNumberFormatter const& & phoneNumber);
public static void TryCreate(string regionCode, out PhoneNumberFormatter phoneNumber);
Public Shared Sub TryCreate (regionCode As String, ByRef phoneNumber As PhoneNumberFormatter)

Parameters

regionCode
String

Platform::String

winrt::hstring

The region code of the new PhoneNumberFormatter.

phoneNumber
PhoneNumberFormatter

On success, a new PhoneNumberFormatter for the requested region code.

On failure, this value is null.

Remarks

The following code snippet demonstrates how to use this method to create a PhoneNumberFormatter for the "BR" region.

using Windows.Globalization.PhoneNumberFormatting;

PhoneNumberFormatter currentFormatter = null;

PhoneNumberFormatter.TryCreate("BR", out currentFormatter);
if (currentFormatter != null)
{
    // use the formatter 
}  
else
{
    // formatter could not be created for the given region. 
    // put your fallback logic here.
}

Applies to