Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reReplace

Status
Not open for further replies.

jesse1

Programmer
Aug 29, 2008
30
0
0
US
I am uploading a csv file and want to limit the fields to letter numbers and spaces. I am using the listfix function to replace empty csv fields with Null. The code below does not seem to work because it does not remove ,'s and .'s

<cfset newI = #listgetAt('#index#',1, ',')#>
<cfif newI neq 'Null'><cfset newi=#REReplace(newi, "[^A-Za-z0-9 ]", "", "ALL")#></cfif>
<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#newi#">,
 
1. Why bother testing for "null"? Even if [blue][tt]newI[/tt][/blue] equals "null" the result of the replace appears the same.

2. For non-numeric values, I found it best to quote the [green][tt]REreplace[/tt][/green] function. If not expecting single or double-quotes in [blue][tt]newI[/tt][/blue], try:

Code:
<CFSET newI="#REreplace('#newI#', '[^A-Za-z0-9]', '', 'All')#">

-TT

[rockband]
 
For non-numeric values, I found it best to quote the REreplace function

Why?

The string "null" is probably used as a replacement for empty elements. Prior to CF8, all list functions ignore empty elements. That can create problems if empty elements are significant (ie with a csv file).

----------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top