I Have a string in the form “123456789”.
While displaying it on the screen I want to show it as 123-456-789.
Please let me knwo how to add the “-” for every 3 numbers.
Thanks in Advance.
I Have a string in the form 123456789. While displaying it on the screen
Share
I’ll go ahead and give the
Regexbased solution:That regex breaks down as follows:
The
"$1-"replacement string means that whenever a match for the above pattern is found, replace it with the same thing (the $1 part), followed by a-. So in"123456789", it would match123and456, but not789because it’s at the end of the string. It then replaces them with123-and456-, giving the final result123-456-789.