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!

cfscript and replace() function

Status
Not open for further replies.

twcman

Programmer
Joined
Jun 28, 2001
Messages
284
Location
US
OK,
I have a string #body#. I know this string has an image tage at the begining. The length of the tag is variable #vCount.len[1]#. Using the replace function all I want to do is place a <BR> at the end so the text following the image tag will appear under the image instead of above. Here is the syntax I have so far:

body1=Replace(#body#,'Left(body,#vCount.len[1]#)','left(body,#vCount.len[1]#)<BR>',&quot;ONE&quot;);

It passes without errors but does not produce desired result.

Thanks,
The only dumb questions are the ones that are never asked
 
This script will put a [COLOR=000080]<br>[/color] tag after every [COLOR=000080]<img>[/color] tag in a string:

=== START CODE EXAMPLE ===
<cfscript>
string = 'This text is before the image
<img src=&quot;images/test.jpg&quot; width=&quot;10&quot; height=&quot;10&quot;>
...and this text if after the image';

string = ReReplaceNoCase(string, &quot;(<img
Code:
[
^>
Code:
]
+>)&quot;
, &quot;\1<BR>&quot;, &quot;ALL&quot;);
</cfscript>

<cfoutput>
[COLOR=000080]<b>[/color]Source:[COLOR=000080]</b>[/color] #HTMLEditFormat(string)#
</cfoutput>
=== END CODE EXAMPLE === - tleish
 
Your code doesn't work because are putting the function &quot;left(...)&quot; inside quotes. The function returns a string so you don't want quotes around it. As you wrote it (assuming that the length is 25), you are replacing the literal string &quot;Left(body,25)&quot; with &quot;Left(body,25)<BR>&quot;. Since that string doesn't exist in your &quot;body&quot; variable, no substitution takes place. You could fix that by removinf the quotes, but why do it in such a hard way (and even harder to read)? Have your tried:
Code:
<cfscript>
body = &quot;original text&quot;;
body1 = body & &quot;<BR>&quot;;
 
a440guy,
Thanks for the input. Your way would work if the image tag was the only text in the #body#. The image tag is the first part of the #body# variable. I am basically inserting the <BR> tag in the middle of the #body# variable. Your way would place it at the end of all the text.
The only dumb questions are the ones that are never asked
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top