Jump to content
Maarten Witberg

parse by any delimiter

Recommended Posts

Maarten Witberg

I'm trying to create a recursive CF that will pick out any string delimited by any two user defined delimiters (as entered in a return-separated list or directly as a text string in a parameter), the CF being

 

ParseByAnyDelimiter ( String ; Start ; Delimiters)

 

where string is the text to be parsed, Start is the number of the left hand delimiter to work from, and Delimiters the list as said above.

 

The silly thing is, I can get the recursion to work, but apparently, the Middle( ) expression that is supposed to do the actual parse, will not return a value unless start = 1. As you can see in the sample, the Middle expression works fine when called in a separate field, as does the recursion which essentially replaces any item in the delimiter list with a "|" pipe character.

 

I must be overlooking something really obvious, but I'm stumped.

 

Please see this thread for the why. I used Ahunter's parse calc for starters.

Share this post


Link to post
Share on other sites
comment

I find your task definition confusing. Let's take a string like:

"123+456-789+000-ABC"

 

The user-defined delimiters are "+" and "-".

 

What is the expected result?

Share this post


Link to post
Share on other sites
comment

Did you perhaps mean something like this?

Share this post


Link to post
Share on other sites
Maarten Witberg

yes, that is what I am looking for, with a slight variation: the result should be that the first occurrence in a string " 123§456§7899" with delimiter § should be "123". That can be fixed by wrapping NewText in your function in § marks...

 

If I look at your function:

- I didn't think about using GetValue. nice.

- the main difference seems to be that you let the recursion happen in the main part of the let function and I, as an expression

 

let ([stuff];recursion) instead of let ([recursion];stuff)

 

I don't understand why yours produces a result and mine, not. I'm afraid that this lack of understanding is why creating recursive CFs costs me so much time. The recursion produces a cleaned-up string in both cases (with all delimiters replaced by "|" or "§"...

 

Thanks for fixing it.

Share this post


Link to post
Share on other sites
comment

Ah, OK, I see what you mean. Yes, the solution is as you indicated (attached).

 

I have to admit I did not truly understand your file. That is more a reflection on my ability to follow other people's logic than on your work. In any case, I don't think the placement of recursion in a Let()statement, or the other way around, makes any difference. The Let() function doesn't actually do anything; you can replace all its variables with their definitions, remove the Let(), and the calculation will continue to work.

 

I am not convinced recursion is even required in this case. The only reason I can see to use a CF is when the possible delimiters are not known beforehand - especially how many of them there will be. That doesn't seem very likely. When the list of valid delimiters is known, you can normalize the string to a single delimiter by using Substitute() with multiple pairs of searchString and replaceString. The rest of the problem is rather trivial.

Share this post


Link to post
Share on other sites
Maarten Witberg
That doesn't seem very likely.

 

Agreed, but I thought it might be handy if the delimiters could be set by users or at least somebody with admin level but not developer level access or skills. especially if the strings to be parsed have a variety of possible delimiters, as seems to be the case in FredP's original post.

 

I have a vague idea of some other uses such as to do an or search on a set of delimiters - the power being you can find which bits of text occur between several strings at once, as the function also allows you to enter multi-character delimiters. Using a wildcard find you'd get the records containing those delimiters, but the string (or occurrence of it) itself would not be readily marked *)

I admit that I don't yet see any practical purpose to this. But it would need a recursive CF I think as long as the user may choose which and how many delimiters.

 

thanks again

 

Maarten

 

edit *) I suppose there are other routes to this result... maybe even more obvious ones...but i am not always good at spotting even the blindingly obvious

Share this post


Link to post
Share on other sites
comment

I agree - partially. You could enable the user to define a LIMITED number of delimiters. For example, this non-recursive formula allows the user to enter UP TO three delimiters into a repeating field:

 

Let ( [

string = "§" & Substitute ( Text ; [ DelimitersR ; "§" ] ; [ DelimitersR[2] ; "§" ] ; [ DelimitersR[3] ; "§" ] ) & "§" ;

start = Position ( string ; "§" ; 1 ; Occurence ) + 1 ;

end = Position ( string ; "§" ; 1 ; Occurence + 1 )

] ;

Middle ( string ; start ; end - start )

)

 

 

Regarding searching, I feel that if you'd ever encounter such a problem, the correct solution would be to normalize the data, rather than trying to dance around it.

Share this post


Link to post
Share on other sites
Maarten Witberg
normalize the data

 

I was not thinking about data that is easily normalisable. For instance largish blocks of text that a user might want to analyse and compare. Perhaps it's better to let the matter rest until a concrete problem presents itself.

Much as I like to dance, there should at least be some purpose when dancing around with filemaker.

 

nice use of repeating field btw.

Share this post


Link to post
Share on other sites
This thread is quite old. Please start a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.




×
×
  • Create New...

Important Information

Terms of Use