Title
leftwords and rightwords eliminating punctuation
Post
Hello all, I'm totally new to the forum but have been dabbling in Filemaker Pro for several years. I'm trying to write a script that will parse a phrase of text, determine how many words are in the phrase, and insert a carriage return halfway through, creating 2 lines from the one phrase. Here's the problem I'm having: I'm using Leftwords and Rightwords to select the different parts of these phrases. The output of these two functions is eliminating all the punctuation in my original phrase, which is unacceptable. I'm sure there's an easier and correct way to do this that will preserve my punctuation. Can anyone lend a hand? Here's the script I wrote to do what I was hoping to do:
put hard CR in long line
Paste [ subtitle::Subtitle entry ]
[ Select ]
Set Field [ subtitle::z; WordCount ( subtitle::Subtitle entry ) ]
Insert Calculated Result [ subtitle::Text holder; LeftWords ( subtitle::Subtitle entry ; Round ( subtitle::z/2 ; 0) ) & "¶" & RightWords
( subtitle::Subtitle entry ; subtitle::z - Round ( subtitle::z/2 ; 0) ) ]
Copy [ subtitle::Text holder ]
If [ (Length ( subtitle::Subtitle entry ) = (Length ( subtitle::Text holder ))-1) and WordCount ( subtitle::Subtitle entry ) = WordCount
( subtitle::Text holder ) ]
Set Field [ subtitle::Pass; "PASSED" ]
Clear [ subtitle::Fail ]
[ Select ]
Else
Set Field [ subtitle::Fail; "FAIL" ]
Clear [ subtitle::Pass ]
[ Select ]
End If
I paste the long line in the field Subtitle entry
then I set the field z = to the word count of that line
Then I insert a calculated result into the field Text holder, taking LeftWords of the field Subtitle entry, and using the word count, z, divided by 2 and rounded to the next whole number, then inserting a carriage return and then taking right words of z- (round(z/2)). Finally I copy the result with the carriage return and run a comparison of that field to the field subtitle entry to make sure they are the same. The comparison requires the word counts to match and the character counts to match (I subtract the carriage return from the text holder to account for the extra character). Frustratingly, all the punctuation disappears (commas, periods the works) in the text holder once I've split the text. Any help would be appreciated! Thanks,
-Andrew
Using LeftWords() and RightWords() should NOT eliminate ALL punctuation marks from the text*. Which version are you using?
---
(*) It will, however eliminate the punctuation marks (and spaces) at the "boundaries", e.g.
Let (
text = " -alpha, bravo, charlie, delta, echo- "
;
LeftWords ( text ; 3 ) & RightWords ( text ; 2 )
)
returns: "alpha, bravo, charliedelta, echo"
The correct way to split the text into two lines would be:
Let ( [
text = " -alpha, bravo, charlie, delta, echo- " ;
splitPoint = Position ( text ; RightWords ( text ; 2 ) ; Length ( text ) ; -1 )
] ;
Replace ( text ; splitPoint ; 0 ; ¶ )
)
This returns:
" - alpha, bravo, charlie, ¶delta, echo - "