Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String.Format("{0:(###) ###-#### x ###}", double.Parse("1234567890123"))
- (d{3})(d{3})(d{4})(d{4})
- (1) 2-3 x4
- class Program
- {
- static void Main(string[] args)
- {
- long phoneNumber = 12345678901234;
- string phoneNumberString = String.Format("{0:(000) 000-0000 x0000}", phoneNumber);
- Console.WriteLine(phoneNumberString);
- }
- }
- public static string InsertStringAtPositions(this string str, string insertStr, IEnumerable<int> positions)
- {
- if (str != null && insertStr != null && positions != null)
- {
- string newString = string.Empty;
- int previousPos = 0;
- foreach (var pos in positions)
- {
- if (pos < str.Length)
- {
- newString += str.Substring(previousPos, pos - previousPos) + insertStr;
- previousPos = pos;
- }
- }
- if (positions.Last() < str.Length)
- {
- return newString + str.Substring(positions.Last(), str.Length - positions.Last());
- }
- return newString;
- }
- return str;
- }
- // Will convert "0399998888" to "03 9999 8888"
- number.InsertStringAtPositions(" ", new[] {2, 6});
Add Comment
Please, Sign In to add comment