How do I run the "contains" decision statement in ColdFusion on a specific character in a string?

My question is super simple, but I can't figure it out. I'm trying to find the "C" character in a seemingly random 10 character string. However, I only care about the "C" character if it is the sixteenth character in the string. If the character "C" is in the sixth position on a string, the string must be enclosed in a dash (-). For example:

14CSI14550 must not be enclosed in a dash because C is the third character on the line. 14EFEC4933 must be enclosed in a dash because C is the sixth character on the line. 14CSIC5005 must also be enclosed in a dash, although there is still a C on the line.

Here is what I have so far, I think I am on the correct path with contains, but I think I need it to start looking for C at the 5th character in the string in order to skip the first 5 characters, I may be wrong.

code:

<cfif #queryName.TenDigitNumber# contains 'C'>
<td width="100" class=bodytext valign="top" >-#Plan.Code#-</td>
<cfelse>
<td width="100" class=bodytext valign="top" >#Plan.Code#</td>
</cfif>

      

This obviously includes all 10 character strings that have a C with a dash, including something like 14CSI14550 which would be wrong. Any help would be appreciated! Thank!

+3


source to share


1 answer


<cfif mid(queryname.tendigitnumber, 6, 1) eq 'C'> .. do stuff .. </cfif>

      



+12


source







All Articles