954,585 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

String Replace?

Good day all,
well i have been searching the web and i cannot find an answer to my question. First off i dont know if i should post this here or in the Javascript section because i am a coldfusion user and didnt know if javascript does this. Second my problem is i want to add a "." after the 3rd character or letter. Ex.

var str = "0222232"
This is where the function would come in to add a . after the 3rd number. So the output would be 022.2232

Is this possible? I normally show code, but i wouldnt even know where to start. Thanks for the help.

fobos
Posting Whiz in Training
297 posts since Feb 2009
Reputation Points: 29
Solved Threads: 52
 

i dont know about coldfusion but you should be able to do something like this
substring(0,3) + "." + substring(4,stringLength)
or if you can use it like a numeric value then just multiply by 1000

divin757
Light Poster
39 posts since Apr 2009
Reputation Points: 18
Solved Threads: 9
 

Thanks divin757,
Your code helped get me started, but then i noticed that it didnt output the whole thing to include the period. So i just changed the value of 4 to 3 and added str to the substrings and length.

var str = "0222232";
document.write(str.substring(0,3) + "." + str.substring(3, str.length))


Again thanks alot.

fobos
Posting Whiz in Training
297 posts since Feb 2009
Reputation Points: 29
Solved Threads: 52
 

I guess i should post what i use now, for others to view.

<cffunction name="convert" access="public" returntype="string">
    <cfargument name="latitude" required="yes" type="any">
    <cfargument name="longitude" required="yes" type="any">
    <cfset var lat = "">
    <cfset var long = "">
    <cfset lat = #replace(ARGUMENTS.latitude,".","")#>
    <cfset long = #replace(ARGUMENTS.longitude,".","")#>
    <cfset lat.substring(2,4)&"."&lat.substring(4,len(lat))>
    <cfset long.substring(1,3)&"."&long.substring(3,len(long))>
    <cfset coord = lat&","& long>
    <cfreturn coord>
</cffunction>
<cfoutput>#convert("E12345.678","N1234.567")#</cfoutput>
fobos
Posting Whiz in Training
297 posts since Feb 2009
Reputation Points: 29
Solved Threads: 52
 

I am not aware with coldfusion although i am in learning process and your tip is helpful for me.

levine
Newbie Poster
8 posts since May 2010
Reputation Points: 10
Solved Threads: 3
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You