Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Separation of telephone numbers by a dot

Community Beginner ,
Jan 19, 2012 Jan 19, 2012

Hello,

Am still newbie in coldfusion.

I have a telephone number of 12 digits, for e.g, +331234567890.

Now I have to replace the country code by 0,i.e, +33 to 0. I have already done that.

My problem is how to separate these 10 remaining numbers and put a dot in between each 2 numbers like 12.34.56.78.90 and at the end join the country code like 0.12.34.56.78.90

I was thinking of doing a Len() of the numbers and then separate them by a dot but unfortunately I don't know how to do it.

Can anybody help me please ?

Thanks in advance.

1.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 19, 2012 Jan 19, 2012

<cfset dotted_reverse_telno = "">

<cfset telno = "01234567890">

<!---Reverse the tel number --->

<cfset reverse_telno = reverse(telno)>

<!---Run through the digits in the reversed number, adding a dot after every 2 digits --->

<cfloop from="1" to="#len(reverse_telno)#" index="n">

    <cfif n mod 2 EQ 0>

        <cfset dotted_reverse_telno = dotted_reverse_telno & mid(reverse_telno, n, 1) & "." >

    <cfelse>

        <cfset dotted_reverse_telno = dotted_reverse_telno & mid(reverse_telno, n, 1)>

    </cfif>

...
Translate
Community Expert ,
Jan 19, 2012 Jan 19, 2012

<cfset dotted_reverse_telno = "">

<cfset telno = "01234567890">

<!---Reverse the tel number --->

<cfset reverse_telno = reverse(telno)>

<!---Run through the digits in the reversed number, adding a dot after every 2 digits --->

<cfloop from="1" to="#len(reverse_telno)#" index="n">

    <cfif n mod 2 EQ 0>

        <cfset dotted_reverse_telno = dotted_reverse_telno & mid(reverse_telno, n, 1) & "." >

    <cfelse>

        <cfset dotted_reverse_telno = dotted_reverse_telno & mid(reverse_telno, n, 1)>

    </cfif>

</cfloop>

<!---Reverse the result --->

<cfset dotted_telno = reverse(dotted_reverse_telno)>

<cfoutput>#dotted_telno#</cfoutput>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jan 19, 2012 Jan 19, 2012

Regex FTW.

<cfset newstr = reReplace(reverse("012456994088"), '([0-9]{2})', '\1.', 'all') />

<cfoutput>#reverse(newstr)#</cfoutput>

Not perfect as it has a dot at the start if it's an even number and not if it's odd, but that's easily fixed.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 19, 2012 Jan 19, 2012
LATEST

Thanks dude.

I did not know that we could make use of regex in coldfusion. Cool..

Yeps this could be easily fixed with the dot at start. Thanks a lot again for the quick reply.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 19, 2012 Jan 19, 2012

Well I have already done half of the code u posted, it's just that I don't know how to separate and put the dot in middle.

Thanks a lot. It helps me loads....

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources