Jump to content
Server Maintenance This Week. ×

Field Parsing Question: Been away too long...


This topic is 4409 days old. Please don't post here. Open a new topic instead.

Recommended Posts

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?

Link to comment
Share on other sites

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 by LaRetta
Link to comment
Share on other sites

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 by Russell Barlow
Link to comment
Share on other sites

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 ) )

)

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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 ) )

)

Link to comment
Share on other sites

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 )

)

)

Link to comment
Share on other sites

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 by LaRetta
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This topic is 4409 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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.