johnrh Posted August 9, 2012 Posted August 9, 2012 I am using a simple pattercount function in the middle of a let statement. _stk = patterncount(myfield,"IM") However I need to distinguish between records where myfield contains values like "slim", "blimp" and just "IM") Can the patterncount function use operators like the find statement? I really need to know how many times the the letters "IM" turn up in the field by them selves i.e. not Slim or Blimp etc. Anybody got any ideas to help please? Thanks
comment Posted August 9, 2012 Posted August 9, 2012 Try perhaps: PatternCount ( " " & MyField & " " ; " IM " ) Note, however, that this will return zero in the following example: "word, IM, another word".
No_access Posted August 9, 2012 Posted August 9, 2012 Seems to me that you should be able to do something like this. Set Variable ($srchterm; Value:"IM") Set Variable [$count; Value:PatternCount(data;$srchterm)] Set Variable ($increment;0) Loop Set Variable ($increment;$increment+1) if [$increment > $count] Exit Script[] end if Set Variable[$position1;Value:Position(data;$srchterm;1;$increment)] /* code here to grab the left couple and right couple characters and check it.. then loop to next occurence. */ end loop
Lee Smith Posted August 9, 2012 Posted August 9, 2012 FMP12? Please update your Profile to reflect your current version of FileMaker Quick Link. TIA Lee
Newbies Peter Bouma Posted August 14, 2012 Newbies Posted August 14, 2012 Let( breakIntoLines = substitute( myField ; [ "," ; "¶¶" ] ; [ "." ; "¶¶" ] ; [ ";" ; "¶¶" ] ; [ ":" ; "¶¶" ] ; [ " " ; "¶¶" ] ; [ ¶ ; "¶¶" ] ) ; // ... and substitute anything else that also could be a word boundary, by double returns as well PatternCount( ¶ & breakIntoLines & ¶ ; ¶ & "IM" & ¶ ) ) NB: I substitute all punctuation by double returns, in order to give each value its 'own' ¶s before and after. Apparently, PatternCount() reads a string sequentially from beginning to end, which means that if a return already has been detected as the conclusion of an occurrence of "¶IM¶", it will not be counted anymore if the next line would contain "IM" again. PatternCount has no memory of its past. BTW, PatternCount is not case-sensitive, but Substitute is. If you really only want the uppercase occurrences of "IM", you could try this: Let([ breakIntoLines = substitute( myField ; [ "," ; "¶¶" ] ; [ "." ; "¶¶" ] ; [ ";" ; "¶¶" ] ; [ ":" ; "¶¶" ] ; [ " " ; "¶¶" ] ; [ ¶ ; "¶¶" ] ) ; // same as above weirdString = "$#$#$#$#$#$#$#$" ; flagUppercaseIM = substitute( breakIntoLines ; ¶ & "IM" & ¶ ; ¶ & weirdString & ¶ ) ]; PatternCount( ¶ & breakIntoLines & ¶ ; ¶ & weirdString & ¶ ) ) Assuming, of course, that your choice of weirdString is unlikely to occur in your field. HTH Peter
LaRetta Posted August 14, 2012 Posted August 14, 2012 (edited) You might also consider taking advantage of the string being all cap "IM". If this is so, and if you can feel comfortable that your regular text would not contain blIMp or BLIMP then you should be safe: PatternCount ( Substitute ( text ; "IM" ; "~" ) ; "~" ) Actually you can smarten it up a bit with: PatternCount ( Substitute ( text ; [ " IM" ; "~" ] ; [ " IM " ; "~" ] ; [ " IM," ; "~" ] ; [ " IM." ; "~" ] ) ; "~" ) Edited August 14, 2012 by LaRetta
comment Posted August 14, 2012 Posted August 14, 2012 (edited) IMHO, the attempt to anticipate all possible punctuation characters is rather naive. If it's important to detect the search string as a word, it would be best to use some xWords functions (in a loop, if necessary) - for example: http://www.briandunning.com/cf/1390 Edited August 14, 2012 by comment
johnrh Posted October 1, 2012 Author Posted October 1, 2012 Thanks to everyone who offered help. I went in the end with the custom function offered by Brian Dunning. Works great. Thanks
Recommended Posts
This topic is 4493 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now