示例#1
0
        /// <summary>
        /// Extracts the subscriber number
        /// </summary>
        /// <param name="parser">An instance of type <see cref="PhoneNumberUtil"/> to parse</param>
        /// <param name="parsedNumber">An instance of type <see cref="PhoneNumber"/> representing the parsed number</param>
        /// <returns>The subscriber number as <see cref="string"/></returns>
        private string GetSubscriberNumber(PhoneNumberUtil parser, PhoneNumber parsedNumber)
        {
            // Get the national relevant number and the length of the area code
            string nationalNumber = parser.GetNationalSignificantNumber(parsedNumber);
            int    areaCodeLength = parser.GetLengthOfGeographicalAreaCode(parsedNumber);

            // Get the substring of the national relevant number from the index of the length of the area code
            string subscriberNumber = nationalNumber.Substring(areaCodeLength);

            return(subscriberNumber);
        }
示例#2
0
        /// <summary>
        /// Retrieves the area code of parsed number
        /// </summary>
        /// <param name="parser">An instance of type <see cref="PhoneNumberUtil"/> representing the parser</param>
        /// <param name="parsedNumber">An instance of type <see cref="PhoneNumber"/> representing the parsed number</param>
        /// <param name="number">The raw number as <see cref="string"/></param>
        /// <returns></returns>
        private string GetAreaCode(PhoneNumberUtil parser, PhoneNumber parsedNumber, string number)
        {
            string areaCode;

            // Get length of area code and the national relevant part of the number
            int    areaCodeLength = parser.GetLengthOfGeographicalAreaCode(parsedNumber);
            string nationalNumber = parser.GetNationalSignificantNumber(parsedNumber);

            // Check if the number starts with "0"
            if (number.StartsWith("0"))
            {
                // Get the area code which starts with a "0"
                areaCode = $"0{nationalNumber.Substring(0, areaCodeLength)}";
            }
            else
            {
                // Get the area code which does not start with a "0"
                areaCode = nationalNumber.Substring(0, areaCodeLength);
            }

            return(areaCode);
        }