This also may not be the most elegant solution, but it works:

<cfset write_toggle = 1>
<cfloop from="#myString_len#" to="1" step="-1" index="i">
        <cfif write_toggle eq 1>
                <cfset myProteinSequence = Insert(" ",myProteinSequence,i)>
        </cfif>
        <cfif mid(myProteinSequence,i,1) eq ")">
                <cfset write_toggle = 0>
        <cfelseif mid(myProteinSequence,i,1) eq "(">
                <cfset write_toggle = 1>
        </cfif>
</cfloop>

-----Original Message-----
From: Richard Colman [mailto:[EMAIL PROTECTED]
Sent: Wednesday, January 12, 2005 3:14 PM
To: CF-Talk
Subject: Conditional text Insert into a String


I have a string that looks like:

 ... KPPET(L ATT)(I GAT)TTID ...

And I want to end up with a string that looks like:

 ... K P P E T (L ATT) (I GAT) T T I D ...

Notice that there is a space in between each letter EXCEPT in the (X YYY)
pattern where YYY has to stay together with NO intervening spaces. ( X YYY )
would be OK too.

Right now, I am adding spaces in a loop:

<cfset myString = "#ProteinSequence#">
<cfset myString_len = Len(myProteinSequence)>

<cfloop from="#myString_len#" to="1" step="-1" index="i">
        <cfset myProteinSequence = Insert(" ",myProteinSequence,i)>
</cfloop>

But this adds spaces everywhere, even where I don't want them , in the "YYY"
pattern, so I get:

 ... K P P E T ( L  A T T ) ( I  G A T ) T T I D ...

If I could do a "conditional insert" where it stops inserting a space when
it hits the first ")" and start again after it hits the next "(" but I am
not sure how to do it?

Any ideas would be appreciated, otherwise I need to explore regular express
replace with backreferences (maybe), which is a prospect too horrible to
contemplate ...

Richard Colman
Institute for Genomics and Bioinformatics






~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Discover CFTicket - The leading ColdFusion Help Desk and Trouble 
Ticket application

http://www.houseoffusion.com/banners/view.cfm?bannerid=48

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:190148
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to