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!

count characters

Status
Not open for further replies.

twcman

Programmer
Joined
Jun 28, 2001
Messages
284
Location
US
I have a string from a database field that contains the <img src=bla bla bla>. I need to count the number of characters between the start and end tag. I know I need to find the < and then count until the code sees a >. But I cannot come up with the code.

The only dumb questions are the ones that are never asked
 
Use the ReFindNoCase() function. Be sure to set the &quot;returnsubexpressions&quot; parameter to true.

=== 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 adter the image';

vCount = ReFindNoCase(&quot;<img
Code:
[
^>
Code:
]
+>&quot;
, string, 1, &quot;True&quot;);
vImg = Mid(string, vCount.pos
Code:
[
1
Code:
]
, vCount.len
Code:
[
1
Code:
]
);
</cfscript>

<cfoutput>
[COLOR=000080]<b>[/color]Position:[COLOR=000080]</b>[/color] #vCount.pos
Code:
[
1
Code:
]
#[COLOR=000080]<br>[/color]
[COLOR=000080]<b>[/color]Length:[COLOR=000080]</b>[/color] #vCount.len
Code:
[
1
Code:
]
#[COLOR=000080]<br>[/color]
[COLOR=000080]<b>[/color]Source:[COLOR=000080]</b>[/color] #HTMLEditFormat(vImg)#
</cfoutput>
=== END CODE EXAMPLE ===




Cold Fusion Manual

REFindNoCase

Description
Returns the position of the first occurrence of a regular expression in a string starting from a specified position, if the returnsubexpressions parameter is not set to True. Returns 0 if no occurrences are found. The search is case-insensitive.

Returns the position and length of the first occurrence of a regular expression in a string, if the returnsubexpressions parameter is set to True.

Category
String functions

Syntax
REFindNoCase(reg_expression, string [, start ]
[, returnsubexpressions ] )

- tleish
 
Great code. thank you. One question, How do i detect if vCount=0 in cfscript. If it equals 0, i do not want to process the mid function. The only dumb questions are the ones that are never asked
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top