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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trim 1

Status
Not open for further replies.

theevilone

IS-IT--Management
Joined
Aug 19, 2001
Messages
52
Location
GB
Hi,

I have a variable, thumb_xxxxx, that is returned from a db. I want to write something that will remove the first 6 characters, leaving just the xxxxx, that is then processed. Can anyone help.

Thanks in Advance,
Ravi
 
#Right(thumb_xxxxxx, 6)#

This will remove the first six characters.

<cfset newText = &quot;#Right(string, count)#&quot;>

DeZiner
Never be afraid to try something new.
Remember that amateurs built the Ark.
Professionals built the Titanic
 
Thanks DeZiner. It worked.
 
I'll note to actually remove the first six characters from a string of any length..

Code:
<CFOUTPUT>#right(string,len(string)-6)#</CFOUTPUT>

Tony Did I help?
Vote!
 
Thanks for the vote, call it even :) Did I help?
Vote!
 
One variant that I've found I'm using more and more is to use ColdFusion's list methods in situations like yours.

Somewhere down the road, I may decide that I don't want to use &quot;thumb_&quot; anymore, or perhaps I'll add functionality that requires other similar naming conventions (like &quot;icon_&quot; or &quot;fullsize_&quot;, etc.).

Rather than have to rewrite my parsing code everytime, I treat the string as a list with a custom delimiter, like:
Code:
<CFSET myString = &quot;thumb_xxxxx&quot;>
<CFSET secondPart = ListGetAt(&quot;#myString#&quot;,2,&quot;_&quot;)>
<CFOUTPUT>#secondPart#</CFOUTPUT>

of course, a check to make sure ListLen(&quot;#myString#&quot;,&quot;_&quot;) GT 1 is always nice so you trap any errors.

Just a thought.

Hope it helps,
-Carl
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top