Removing newline from textarea form string

Discussion in 'Programming' started by moose123, Nov 5, 2009.

  1. #1
    Hi,

    I have a textarea on a form, and the form writes out to a CSV using <CFFILE>. The problem I'm having is that when text from the textarea has a new line or a single carraige return, it messed up the CSV by creating a new field, and thus making it unusable when we import it into Excel. I've tried both the following snippets, and while they both work for removing multiple carriage returns, they don't remove single newlines for some reason.

    <cfset abstract_text = Replace(abstract_text, "#chr(10)##chr(13)#", "", "ALL")>

    ...and...

    <cfset abstract_text = ReReplace(abstract_text, "[\r\n]+\t*[\r\n]*", "#Chr(10)#", "ALL")>

    I'm running CFMX on Windows 2000. Thanks for any help.
    Moose
     
    moose123, Nov 5, 2009 IP
  2. cfStarlight

    cfStarlight Peon

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Well... if it is not replacing them, that strongly suggests to me the sequence of characters is not what you think it is. The best thing to do is examine the input string and find out what character(s) _are_ there ;-) Use the MID() and ASC() functions to check the ascii values of individual characters:

    <cfoutput>
    ascii value is = #asc(mid(str, somePosition, 1))#
    </cfoutput>

    BTW: You don't need the # signs. A more elegant way to write it is:

    ... Replace(abstract_text, chr(10)&chr(13),"", "ALL")>
     
    cfStarlight, Nov 7, 2009 IP