Trouble using Replace() function in CFN file

Ask a Question related to Macromedia ColdFusion, Design and Development.

  1. #1

    Default Trouble using Replace() function in CFN file

    I don't do much scripting in coldfusion besides some of the very basics for
    trasfering info from the database, so I'm not sure how to write this....

    This is what I've put together so far, which of course does not work. Any
    help would be appreciated, I've been at it a while now.

    So both TextBlock1 and TextBlock2 are fields which I'm taking from the
    database, and trying to do a Replace, to take out the \r in them, since in my
    flash front end, I'm getting multiple carriage returns within the text blocks.
    So if anyone knows the syntax issues I'm having with the Replace function
    below, please let me know.

    Thanks in advance

    ................previous info left out...........
    SELECT *
    FROM pdTable1
    WHERE TestID='#ID1#'
    LIMIT #OrderNum#,1
    </cfquery>


    <cfif IsDefined("TextBlock1")>
    Replace(#TextBock1#,"\r","","ALL")#
    <cfoutput>#TextBock1_mod#</cfoutput>
    </cfif>

    <cfif IsDefined("TextBlock2")>
    Replace(#TextBock2#,"\r","","ALL")#
    <cfoutput>#TextBock2_mod#</cfoutput>
    </cfif>


    jay54321 Guest

  2. Similar Questions and Discussions

    1. Replace function
      Please help, I want to replace a string within field in a table with a nother string. I am using the replace function but I am doing something...
    2. Replace string query - double trouble!
      UPDATE `tableName` SET `fieldName` = REPLACE(fieldName,"stringOne","stringTwo") I use the above code to strip strings from my table, and most of...
    3. Search & Replace Function?
      I have some textfield that users will enter data into on my web site and then I'll use php and write it to mysql - for security purposes, is there...
    4. Using Replace function to remove two different characters
      I'm using replace function to strip 0s from a particular string: <%=replace(rs1("racelength"),"0","''"%> but I need to also strip empty spaces...
    5. Text Replace function
      Hi - I'm using the replace function to hilite search words in text which is returned. However, as the text which is being searched also includes...
  3. #2

    Default Re: Trouble using Replace() function in CFN file

    Unless the "\r" is actually stored in the database as a litteral string, you
    will need to search and replace chr(10) and chr(13)...

    give this a try:



    <cfset newLine = chr(10) & chr(13)>

    <cfoutput query="queryName">
    <cfset TextBock1_mod = Replace(TextBock1, newLine ,"" ,"ALL")>
    #TextBock1_mod#
    <cfset TextBock2_mod = Replace(TextBock2, newLine ,"" ,"ALL")>
    #TextBock2_mod#
    </cfoutput>

    CRidgway Guest

  4. #3

    Default Re: Trouble using Replace() function in CFN file

    I'm still having trouble incorporating the code which was posted....... This
    is what I have so far...........
    I'm pretty unfamiliar with CFN, where I'm not sure the best place to put the
    code which was posted. I'm trying various things, but so far nothing. The
    location it is now, still outputs the old information, and if I put it anywhere
    else it doesn't work at all. Thanks again in advance.

    <cfsetting enablecfoutputonly="YES">


    <cfset EVendorID1 = form.EVendorID1>
    <cfset OrderNum = form.OrderNum>

    <cfset newLine = chr(10) & chr(13)>


    <cfquery name="PCheck" datasource="EW" timeout="10" debug username="root"
    password="abc">
    SELECT *
    FROM product1
    WHERE VendorPD1='#EDEVendorID1#'
    LIMIT #OrderNum#,1
    </cfquery>



    <CFOUTPUT QUERY="PCheck">

    <cfset TextBlock1_mod = Replace(TextBlock1, newLine ,"" ,"ALL")>
    <cfset TextBlock2_mod = Replace(TextBlock2, newLine ,"" ,"ALL")>

    <!---<cfif (#Pass#) IS (#VenPass1#)>--->
    <cfset returnToFlash = "&writing=Acq&, &TimeOfOrder=#TimeSTMP1#&">
    <!---</cfif>--->
    </CFOUTPUT>

    <!---<cfset returnToFlash = "&writingTEMP=NA&">--->

    <!--- FlashOutput contains the string that will be sent back to Flash--->
    <cfprocessingdirective suppresswhitespace="Yes">
    <cfoutput>
    #returnToFlash#
    </cfoutput>
    </cfprocessingdirective>

    jay54321 Guest

  5. #4

    Default Re: Trouble using Replace() function in CFN file

    There is a typo in the setting of newline.
    It should be:
    <cfset newLine = chr(13) & chr(10)>

    If you speak hex, it's easy to remember as DOA (0x0D0A) :P .

    To remove all doubt, you can also remove the \r and \n seperately like this:

    <cfset TextBlock1_mod = Replace (TextBlock1, Chr(13),"" ,"ALL")>
    <cfset TextBlock2_mod = Replace (TextBlock2, Chr(13),"" ,"ALL")>

    <cfset TextBlock1_mod = Trim (Replace (TextBlock1, Chr(10),"" ,"ALL"))>
    <cfset TextBlock2_mod = Trim (Replace (TextBlock2, Chr(10),"" ,"ALL"))>

    (I added Trim() which may also be needed here.)

    Regards,
    -- MikeR


    MikerRoo Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139