Inserting a character for a every three digits in a number

I have a number “030020015014584”
and I have to insert “.” after 3 digits from left and then “-” for next three digits and “.” after two digits.
my expected output:
can any one please help me using substring,split,regular expression


Please try the following:

str = "030020015014584"
pattern = "(\d{3})(\d{3})(\d{2})(\d+)"
replacement = "$1.$2-$3.$4"
result = System.Text.RegularExpressions.Regex.Replace(str, pattern, replacement)

Thanks @msan it is working and can we get the same using split and string?

You could do it by chaining substrings but I don’t think it’s worth it.

String.Substring Méthode (System) | Microsoft Docs

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.