December 19, 201312 yr 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
December 19, 201312 yr Hi Dani, Try: LeftWords ( Substitute ( field ; 0 ; ",0" ) ; WordCount ( field ) )
December 19, 201312 yr Cute trick with the LeftWords(). How about a shorter one: Substitute ( "§" & field ; [ "0" ; ",0" ] ; [ "§," ; "" ] )
December 19, 201312 yr Dang! I do like yours better - and it is shorter!! Oh. Do I dare? That's what she said ! "§," That is just plain genius.
December 21, 201312 yr Author 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 .
December 21, 201312 yr 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, 201312 yr by LaRetta
December 21, 201312 yr 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, 201312 yr by eos
December 21, 201312 yr 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 …
December 21, 201312 yr 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
December 21, 201312 yr 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 …
December 21, 201312 yr 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.
December 21, 201312 yr @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, 201312 yr by comment
December 21, 201312 yr 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.
December 21, 201312 yr @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.
December 21, 201312 yr 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.
January 5, 201412 yr Author 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
Create an account or sign in to comment