Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

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

Recommended Posts

Posted

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

Posted

Dang!  I do like yours better - and it is shorter!!

 

Oh.  Do I dare?

 

That's what she said ! :jester:


"§,"

 

That is just plain genius.

Posted (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 by LaRetta
Posted (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 by eos
  • Like 1
Posted

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 …

Posted

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 …  :smile:

Posted

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.

Posted (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 by comment
Posted

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.

Posted

@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.

Posted

As long as I am "lecturing" :cool: , 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.

  • 2 weeks later...

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