[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 245
  • Last Modified:

Cold Fusion Text Formatting

I need a bit of help with Cold Fusion text trimming and formatting.

I have a string that will output from the database looking like this

The McDermont 72in
The Shea 55in
etc...

I need to make them display without the measurements. My plan was to do the following:

* Get the position of the second space
* Trim off everything to the right of that
* Save that into a variable and use that as the display

I need help with the function to find position of the second occurance of a space
AND
I need help with the command to capture the portion of the string I want using the value from the first function.

Thanks
0
comfixit
Asked:
comfixit
1 Solution
 
stu215Commented:
there are three functions you could use to do this :

LEFT              : Left(string, count)
MID               : Mid(string, start, count)
and RIGHT      : Right(string, count)

For your goal, Id suggest MID, however all of those functions require that you know where you want to start in the string.
if the end part is always 4chars then you could do :

<cfset temp=#<yourstring>.length#>
<cfset #temp#=#temp#-4>

Using Mid :
#Mid(<yourstring>, 0, temp)#    

Using Left :
#Left(<yourstring>, temp)#

~Stu :-)
0
 
DJAriganCommented:
<!--- Here: --->
<CFSET temp = "The McDermont 72in">

<!--- To get the position of the second space use: --->
<CFSET p = find(temp, " ", find(temp, " ") + 1)>

<!--- Removing everything aftwards --->
<CFSET temp = left(temp, p - 1)>
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now