/** * Helper method to get the national-number part of a number, formatted without any national * prefix, and return it as a set of digit blocks that would be formatted together. */ private static String[] GetNationalNumberGroups(PhoneNumberUtil util, PhoneNumber number, NumberFormat formattingPattern) { if (formattingPattern == null) { // This will be in the format +CC-DG;ext=EXT where DG represents groups of digits. String rfc3966Format = util.Format(number, PhoneNumberFormat.RFC3966); // We remove the extension part from the formatted string before splitting it into different // groups. int endIndex = rfc3966Format.IndexOf(';'); if (endIndex < 0) { endIndex = rfc3966Format.Length; } // The country-code will have a '-' following it. int startIndex = rfc3966Format.IndexOf('-') + 1; return(rfc3966Format.Substring(startIndex, endIndex - startIndex).Split(new [] { '-' })); } else { // We format the NSN only, and split that according to the separator. String nationalSignificantNumber = util.GetNationalSignificantNumber(number); return(util.FormatNsnUsingPattern(nationalSignificantNumber, formattingPattern, PhoneNumberFormat.RFC3966).Split(new [] { '-' })); } }
/// <summary> /// Helper method to get the national-number part of a number, formatted without any national /// prefix, and return it as a set of digit blocks that should be formatted together according to /// the formatting pattern passed in. /// </summary> private static IList <string> GetNationalNumberGroups(PhoneNumberUtil util, PhoneNumber number, NumberFormat formattingPattern) { // If a format is provided, we format the NSN only, and split that according to the separator. var nationalSignificantNumber = util.GetNationalSignificantNumber(number); return(util.FormatNsnUsingPattern(nationalSignificantNumber, formattingPattern, PhoneNumberFormat.RFC3966).Split('-')); }