removing characters from string "removeCars"

Hi, I am in the process of cleaning up some tables. There are 2500 entires in a field which need work. The form of the entries is DFQSDQSFQSDF.mp3 where the letters are different mp3 names. I am looking at these as individual strings and trying to use the RemoveChars function in coldfusion 8.

Problem
 I need to be able to set the second variable in this function to the length of each string presented by the output function - to get the lenght of the string I have used  the len function. Below is the code, which does not seem to work unless I put a real number in for the second variable in the RemoveChars function.

Would seem the problem lies with the structure I am using for the second variable.

Many thanks for any help.
++++++++++++++++++++++++++CODE++++++++++++++++++++++++++++++
<cfoutput query="recordset1">
<CFSET No = #len(recordset1.MP3)#>

#RemoveChars(recordset1.MP3,
    #No#, 4)#&nbsp;#len(recordset1.MP3)# <br />

      </cfoutput>

jameskaneAsked:
Who is Participating?
 
azadisaryevConnect With a Mentor Commented:
#left(recordset1.mp3, len(rerodset1.mp3)-4)#
#listfirst(recordset1.mp3, ".")#
#replacenocase(recordset1.mp3, ".mp3", "")#
#removechars(recordset1.MP3, len(recordset1.mp3)-3, 4)#

all the above will do what you want, however... if you are trying to update a db table, you might as well do it inside your db... a simple UPDATE query using your db's built-in string functions will do the trick.
what's your db?

Azadi
0
 
azadisaryevCommented:
first, do not name your variables No - no is equivalent of false, which is a reserved word and naming your vars that may cause you all sorts of head-scratching.

second, the second attribute of removechars() function is "Position at which to start search."
if you set, like you do, to the length of the string, then it obviously won;t remove anything because there are no characters after the last in the string...

if you just explain what exactly you want to remove from your string, we will show you how to do it best. removechars() may not not be the best approach in your case.

Azadi

0
 
jameskaneAuthor Commented:
Thanks very much. What I have is a table with a column of data that needs cleaning up. The column field name is MP3. The entries are the names of music - all ending with .MP3. I want to eliminate the . mp3 from the end of each entry.

So I created a record set and then used cfoutput to get a listing. Following that, I select the list from the browser and then paste it into the MP3 field. Bit crude I know.

I redid the code based on your input  as follows

<cfoutput query="recordset1">
<CFSET start = (#len(recordset1.MP3)# - 4)>

#RemoveChars(recordset1.MP3,
    #start#, 4)#<br />

      </cfoutput>



However, I get the following error
===========================================================================
Missing argument name.

When using named parameters to a function, every parameter must have a name.
The CFML compiler was processing:

An expression beginning with RemoveChars, on line 20, column 2.This message is usually caused by a problem in the expressions structure.
The body of a cfoutput tag beginning on line 17, column 2.
 
Resources:
Enable Robust Exception Information to provide greater detail about the source of errors. In the Administrator, click Debugging & Logging > Debug Output Settings, and select the Robust Exception Information option.
Check the ColdFusion documentation to verify that you are using the correct syntax.
Search the Knowledge Base to find a solution to your problem.
Browser        Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.1.249.1036 Safari/532.5
Remote Address        127.0.0.1
Referrer        
Date/Time        24-Mar-10 04:41 PM

==============================================================
Thanks again for the help !!

James

0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
jameskaneAuthor Commented:
SDance

thanks very much !!
0
 
azadisaryevCommented:
hmm... what's SDance? the name of your cf dsn or db table?

what i meant is: what dbms are you using? ms sql server? mysql? postgre? ms access?

Azadi
0
 
jameskaneAuthor Commented:
Sorry, the dsn is SDance and the table is MUSICLINKS. The database is MS ACCESS
0
 
azadisaryevCommented:
try this:

UPDATE musiclinks
SET somecolumn = LEFT(mp3, LEN(mp3)-4)

replace 'somecolumn' with name of column you want to store the filename without .mp3 in.

as always, please remember to back up your db before running the above query.

Azadi
0
 
jameskaneAuthor Commented:
Thanks Azedi, good advice, I was just being lazy. Used cfquery instead of update as I read somewhere that update only works from a form input. Anyhow, below is the code for anyone else who might be interested.

Again, very many thanks for your help !!

Jim

<cfoutput query="recordset1">
<cfset mp3 = #mp3#>


<CFQUERY
dataSource = "SDANCE">
    UPDATE musiclinks
   
    SET MP3 = '#LEFT(mp3, LEN(mp3)-4)#'
WHERE ID = #ID#
</CFQUERY>
</cfoutput>
0
 
jameskaneAuthor Commented:
really helpful
0
 
jameskaneAuthor Commented:
sorry, I thought I had closed this out. Went through the menu and it seems to have closed. Must have done something wrong. Apologies for delay in closing out

james
0
All Courses

From novice to tech pro — start learning today.