Phonenumber utils: Parsing and Formatting Phone Numbers
This tutorial demonstrates how you can parse and format phone numbers.
This feature is supported in mobile applications only.
Warm-up
Become familiar with the Phonenumber utils API basics by learning about:
-
Getting the Location
Get the location based on the region and language.
-
Formatting the Number
Get the number formatted based on the region.
Getting the Location
To get the location from the phone number:
-
To use the functions and data types of the Phonenumber utils API, include the <phone_number.h> header file in your application:
#include <phone_number.h>
-
To get the location, use the phone_number_get_location_from_number() function:
int ret; char *location = NULL; ret = phone_number_get_location_from_number("0222550114", PHONE_NUMBER_REGION_REPUBLIC_OF_KOREA, PHONE_NUMBER_LANG_ENGLISH, &location); if (PHONE_NUMBER_ERROR_NONE == ret) { // Use location // location – "Seoul" dlog_print(DLOG_DEBUG, LOG_TAG, "location=%s", location); } free(location);
Formatting the Number
To format the phone number:
-
To use the functions and data types of the Phonenumber utils API, include the <phone_number.h> header file in your application:
#include <phone_number.h>
-
Use the region to format the phone number:
int ret; char *formatted_number = NULL; ret = phone_number_get_formatted_number("0222550114", PHONE_NUMBER_REGION_REPUBLIC_OF_KOREA, &formatted_number); if (PHONE_NUMBER_ERROR_NONE == ret) { // Use formatted_number // formatted_number - "02-2255-0114" dlog_print(DLOG_DEBUG, LOG_TAG, "formatted_number=%s", formatted_number); } free(formatted_number);