Filemaker

Материал из Wiki Mininuniver
Перейти к навигацииПерейти к поиску

Situation( PatternCount( Haystack Needle ) &gt

Replace( Haystack  Placement( Haystack  Needle  1  one )  Duration( Needle )  Substitute )
Haystack)
 Using the developed-in Situation function (given that there are only two situations, the If perform could be utilized here as well), we examination for the existence of Needle in Haystack with the designed-in PatternCount operate:

PatternCount ( Haystack Needle )&gt0 For the genuine situation, we print the effects of the constructed-in Substitute(textstartnumberOfCharactersreplacementText) perform.

Change ( Haystack Position ( Haystack Needle 1 1 ) Duration ( Needle ) Alternative ) The alternative within just Haystack starts off at the position of the initial instance of Needle and extends the variety of people of Needle and is changed by Substitute.

For the false or default scenario, we only print Haystack given that there is no Needle to exchange.

Global Search and Replace Purpose 

Operate Title: String Substitute

Parameters:

Needle - This parameter signifies the substring for which we want to search.

Substitute - This retains the string that will substitute the substring in Needle.

Haystack - This parameter holds the complete string to research: the proverbial Haystack in which to locate and substitute the Needle, if you will.

Functionality Entire body:

If( PatternCount( Haystack Needle ) &gt

Let( pos = Situation( Haystack Needle one 1 ) + Duration( Needle )

Permit(

[ HaystackBegin = Situation( pos &gt Remaining( Haystack pos - one ) "" )

HaystackEnd = Center ( Haystack pos Size( Haystack ) - pos + 1 )

]

String Replace( Needle Alternative HaystackBegin ) &amp String Replace All( Needle Substitute HaystackEnd )

)

)

Haystack)   Our foundation condition listed here is a Haystack with  situations of Needle. Right here we only output the Haystack.

For a defining issue, when Haystack has a lot more than circumstances of Needle (it can never ever have a adverse number of circumstances, of course), we replace the first instance and contact this purpose recursively with the remaining Haystack. With each call, there will be 1 significantly less Needle in the Haystack, till the foundation situation is achieved where Needles exist in the Haystack.

Utilizing the constructed-in If function, we do a take a look at for a non-foundation affliction which is a Haystack with one or additional occasion of Needle.

PatternCount( Haystack Needle ) &gt The cause we really don't check immediately for the base issue (i.e.PatternCount ( Haystack Needle ) = ), is that in some instances, these as when Haystack is vacant, the PatternCount perform could return an undefined worth, which is neither nor greater than , but need to consequence in a base issue return.

If the issue is true, there are Needles in the Haystack, so we set these variables:


pos = Situation( Haystack  Needle  one  one ) + Size( Needle ) - The character posture inside Haystack instantly next the very first occasion of Needle.
HaystackBegin = Scenario( pos &gt   Still left( Haystack pos - 1 )  "" ) - The articles of the Haystack string up to posture pos. This string will incorporate exactly one instance of Needle 
HaystackEnd = Center( Haystack  pos  Size(Haystack) - pos + 1 ) - The remaining content of Haystack that contains one particular a lot less instance of Needle. 
Then, we print the result of HaystackBegin with its solitary occasion of Needle changed and concatenated(&amp) with the recursive contact to String Change All with the remaining Haystack.

String Swap( Needle Substitute HaystackBegin ) &amp String Substitute All( Needle Alternative HaystackEnd ) Lastly, when the PatternCount affliction is false, we simply print Haystack.


hosting, FM0-304 - Increase Your Filemaker 10 Abilities!, filemaker