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 derfloh 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
Joined
Aug 29, 2008
Messages
30
Location
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.

Similar threads

  • Locked
  • Question Question
Replies
2
Views
181
Replies
3
Views
195
  • Locked
  • Question Question
Replies
0
Views
116

Part and Inventory Search

Sponsor

Back
Top