Dani Rubenstein Posted December 19, 2013 Posted December 19, 2013 hi to all i have a filed that name tagA. in the filed i have tag numbers that are stored "010203040506". how can i separate then bt script that that will stored in filed tagB :"01,02,03".. the length of the string can be longer to shooter thanks Dani
LaRetta Posted December 19, 2013 Posted December 19, 2013 Hi Dani, Try: LeftWords ( Substitute ( field ; 0 ; ",0" ) ; WordCount ( field ) ) 1
comment Posted December 19, 2013 Posted December 19, 2013 Cute trick with the LeftWords(). How about a shorter one: Substitute ( "§" & field ; [ "0" ; ",0" ] ; [ "§," ; "" ] ) 1
LaRetta Posted December 19, 2013 Posted December 19, 2013 Dang! I do like yours better - and it is shorter!! Oh. Do I dare? That's what she said ! "§," That is just plain genius.
Dani Rubenstein Posted December 21, 2013 Author Posted December 21, 2013 Tanks to all. my mistake in the filed TagA it cab be number like "11" or "21" or "32" etch tag is a two number digit .
LaRetta Posted December 21, 2013 Posted December 21, 2013 (edited) Hi Dani, If there is a way with regular calc, I can't think of it. You could use script but YUK. You can also use custom function, something like this: PairUp ( string ) Let ( chars = Left ( string ; 2 ) & " " ; Substitute ( TrimAll ( chars & Case ( not IsEmpty ( string ) ; PairUp ( Right ( string ; Length ( string ) - 2 ) ) ; string ) ; 0 ; 0 ) ; " " ; "," ) ) // end let Edited December 21, 2013 by LaRetta
LaRetta Posted December 21, 2013 Posted December 21, 2013 Repetitions! Maybe repetitions could poor man's recurse!
eos Posted December 21, 2013 Posted December 21, 2013 (edited) If there is a way with regular calc, I can't think of it. You could use script but YUK. You can also use custom function, something like this: or a wee bit more structured as ChunkSplit ( string ) = Let ( [ s = string ; len = Length ( s ) ; c = 2 ; sep = "," ; r = Left ( string ; 2 ) ; rem = Middle ( string ; 3 ; Length ( string ) - 2 ) ] ; r & Case ( Length ( rem ) ; "," & ChunkSplit ( rem ) ) ) EDIT: As per comment's comment, reworked without the reassigning … ChunkSplit ( string ) = Let ( [ r = Left ( string ; 2 ) ; rem = Middle ( string ; 3 ; Length ( string ) - 2 ) ] ; r & Case ( Length ( rem ) ; "," & ChunkSplit ( rem ) ) ) Edited December 21, 2013 by eos 1
eos Posted December 21, 2013 Posted December 21, 2013 PairUp ( string ) Let ( chars = Left ( string ; 2 ) & " " ; Substitute ( TrimAll ( chars & Case ( not IsEmpty ( string ) ; PairUp ( Right ( string ; Length ( string ) - 2 ) ; string ) ; 0 ; 0 ) ; " " ; "," ) ) // end let Wanted to try it out, but the recursive call has a wrong parameter count …
Dani Rubenstein Posted December 21, 2013 Author Posted December 21, 2013 thanks for the help where do i put the TagA and where?
LaRetta Posted December 21, 2013 Posted December 21, 2013 Hi Oliver! I'm not sure I understand the problem you are pointing out. Of course I test before I post and it appears to work just fine (please see attached). :-) PairUp.fmp12.zip
eos Posted December 21, 2013 Posted December 21, 2013 Hi Oliver! I'm not sure I understand the problem you are pointing out. Of course I test before I post and it appears to work just fine (please see attached). :-) Hi LaRetta – your file works just fine, but the code in the file isn't the same as the one in your post. Copy that code from the post, create a new PairUp CF from scratch with the ‘string’ parameter and paste in the code. Try to close the dialog …
LaRetta Posted December 21, 2013 Posted December 21, 2013 I copied from my file, pasted here into code, to create this response, moved a few lines to try to pretty it up. It is the same solution I presented and it indeed works.
comment Posted December 21, 2013 Posted December 21, 2013 (edited) @Dani: You should explain what this is about. It sounds like you are dealing with imported data. If so, you can easily use a script - as part of the import routine - to split the strings into pairs. It would probably be smarter to make each pair a value - i.e. separate them by a carriage return. It could be even better to create a separate related record for each. It all depends on what you plan to do with them. As it happens, inserting a comma after every second character is a nice exercise in recursive processing - but it serves no practical purpose that I can see. In Filemaker terms, you are just turning one big meaningless string into another. @eos: This: s = string ; and this: c = 2 ; is "not done". In the first case, you already have a name bound to a value; there is no good reason to bind another name to the same value (other than to add confusion, waste some RAM and add a few CPU cycles ...). Values are not hot tea; you don't need to pour them from one glass to another. In the second case, 2 is 2 - it makes no sense to give it a name. If you want to make the length a customizable value, add another parameter to the function. BTW, a better name for such function would be Tokenize ( text ; tokenLength ). --- Or Tokenize ( text ; tokenLength ; separator ) - since the same thing applies to the sep variable bound to a comma.. Edited December 21, 2013 by comment
LaRetta Posted December 21, 2013 Posted December 21, 2013 I corrected the single missing parenthesis. It was when it split 'string' and I was trying to fix it and line it up. Thanks for the catch.
eos Posted December 21, 2013 Posted December 21, 2013 @eos: [ … ] Thanks for the lecture, and I don't mean that ironically. When posting in this forum, I try to remain “un-'comment’ed”, which hopefully over time will raise my coding standards, either way.
comment Posted December 21, 2013 Posted December 21, 2013 As long as I am "lecturing" , I should probably add: There's nothing wrong with parametrizing a function (or a calculation) from within, for example: Tokenize ( text ) = Let ( [ // CUSTOMIZE THESE TO FIT YOUR APPLICATION tokenLength = 2 ; separator = "," ; // DO NOT MODIFY FROM THIS POINT ON ... ) This allows the integrating developer to customize the function without unnecessarily exposing the additional parameters at each call of the function. Ideally, they should replace each occurrence of the parameter with the appropriate value - but in a complex custom function, where the parametrized value can be used several times, this may not be practical.
Dani Rubenstein Posted January 5, 2014 Author Posted January 5, 2014 Thanks you all for the help. after i tried it , and i found out that i have a problem i have between etch 2 numbers i have a "¶". is there away i can change it the ¶ a Comma? Tanks
Recommended Posts
This topic is 3974 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