This seems to work but it's inelegant and surprisingly slow. I'm sure
there's a better way....
<cfset myString = "KPPET(L ATT)(I GAT)TTID">
<!--- swap out hard-spaces --->
<cfset placeHolder = chr(7)>
<cfset myString = replace(myString, " ", placeHolder, "all")>
<!--- add soft-spaces --->
<cfset myString = reReplace(myString, "(.)", "\1 ", "all")>
<!--- remove soft spaces inside parentheses --->
<cfset newLength = len(myString)>
<cfset notDone = true>
<cfloop condition="#notDone#">
<cfset myString = reReplace(myString, "(\([^ )]*) ", "\1", "all")>
<cfset oldLength = newLength>
<cfset newLength = len(myString)>
<cfset notDone = newLength neq oldLength>
</cfloop>
<!--- swap back in hard-spaces --->
<cfset myString = replace(myString, placeHolder, " ", "all")>
<cfoutput>#myString#</cfoutput>
-----Original Message-----
From: Richard Colman [mailto:[EMAIL PROTECTED]
Sent: Thursday, 13 January 2005 11:14 a.m.
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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Purchase Contribute 3 from House of Fusion, a Macromedia Authorized Affiliate
and support the CF community.
http://www.houseoffusion.com/banners/view.cfm?bannerid=53
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:190142
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