April 11, 201213 yr Well it's been years since I touched Filemaker, as it just never came up, but now I'm working in it again and I am finding myself slowly getting back in. I have a problem with parsing data out of a field and I hope someone can help me out, as it may be a simple calculation...or it may not be. Anyway...I've got a field from a distributor that I believe is using SAP and they export this field in a garbage in/out format which comes into Filemaker as: GROCERYSTORENAME # 6345 - LOS ANGELES, CA sometimes it doesn't have the store number: GROCERY STORE NAME - BOSTON, MA What I want to do is extract the store name, city, and state...and of course I've got some fun characters occasionally in there like the pound and the dash. Can anyone help me in getting my brain around this stuff again?
April 11, 201213 yr Hi Alan, # and - are word separators so they are actually easy to ignore. Your example shows a dash between the store and the city. Is that always the case? Or is that dash always (at least) the LAST dash in the string? And is the state always two character word at the end? If dash is always what separates, you can use this. I suggest you create the calc and observe the results before using it in script: Trim ( GetValue ( Substitute ( text ; "-" ; ¶ ) ; 1 ) ) However, pinning down the rules a bit more would be in order to be sure we address all possibilities. :^) ooops - wrap with Trim() to remove leading and trailing spaces Edited April 12, 201213 yr by LaRetta
April 12, 201213 yr Author Yes that "-" dash is always there and yes the State is always 2 characters at the end. Thanks...I'll try this and let you know how it turns out.
April 12, 201213 yr Author That worked great...however...any thought as to getting the city out since some have one word and some have two? BTW...I'm enjoying being back in FMP...and 12 is fantastic.
April 12, 201213 yr any thought as to getting the city out since some have one word and some have two? Let ( [ start = Position (YourField ; "-" ; 1 ; 1 ) + Length ( "-" ) ; end = Position ( YourField ; "," ; start ; 1 ) ] ; Trim( Middle ( YourField ; start ; end - start ) ) ); "" ) Edited April 12, 201213 yr by Russell Barlow
April 12, 201213 yr I am sorry ... I was just responding when I realized that, if that company name accidentally has a dash, your calculation will break. So I suggest a different calc approach which looks for the last dash. Company Name Let ( [ num = PatternCount ( text ; "-" ) ; pos = Position ( text ; "-" ; 1 ; num ) ] ; Trim ( Left ( text ; pos - 1 ) ) ) City Let ( [ num = PatternCount ( text ; "-" ) ; pos = Position ( text ; "-" ; 1 ; num ) ; line = Right ( text ; Length ( text ) - pos ) ] ; Trim ( LeftWords ( line ; WordCount ( line ) - 1 ) ) )
April 12, 201213 yr Author Wow...thanks so much...that was perfect. I'm in the process of consolidating all the data from multiple sources...distributors, the SAP database, etc... I was working in the SAP system here and was shocked at how painful it was compared to FMP...but I've been out of FM so long now I'm still getting my brain back into writing calcs...hopefully I can move us over to FMP12 and out of SAP as some point. Thanks again!
April 12, 201213 yr Let ( [ start = Position (YourField ; "-" ; 1 ; 1 ) + Length ( "-" ) ; end = Position ( YourField ; "," ; start ; 1 ) ] ; Trim( Middle ( YourField ; start ; end - start ) ) ); "" ) Shouldn't this be Let ( [ St = Position ( Text ; "-" ; 1 ; 1 )+ Length ( "-" ) ; end = Position ( Text ; "," ; st ; 1 ) ] ; Trim (Middle ( Text ; st ; end - st ) ) )
April 12, 201213 yr I am sorry ... I was just responding when I realized that, if that company name accidentally has a dash,... I don't see that in what they posted? Of course these eyes are old and miss a lot of things. Here is what I was going to post. Trim ( Let ( [ prefix = "-"; suffic = "," ; start = Position ( Text ; prefix ; 1 ; 1 ) + Length ( prefix ) ; end = Position ( Text ; suffic ; start ; 1 ) ] ; Middle ( Text ; start ; end - start ) ) )
April 12, 201213 yr Nice one, Lee!!! But it breaks if there is another dash, such as in the middle of the company name "Smith Hardware - South Division" etc. which is why I ended up changing mine, LOL. Edited April 12, 201213 yr by LaRetta
April 12, 201213 yr Yep. and as you know, it is better for everyone to see actual data, or the source, because there is often other keys that we can use, or hurdles to be allowed for such as your point about the company.
April 12, 201213 yr True, I looked at dash (and then final dash), comma, space between city and state... Mine will break if there is a dash in the city so let's hope a city never names itself South-Side, LOL.
Create an account or sign in to comment