Skip to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

separate a long string

Featured Replies

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

Hi Dani,

 

Try:

LeftWords ( Substitute ( field ;  0 ; ",0" ) ; WordCount ( field ) )

Cute trick with the LeftWords(). How about a shorter one:

Substitute ( "§" & field ; [ "0" ; ",0" ] ; [ "§," ; "" ] )

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.

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

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

Repetitions!  Maybe repetitions could poor man's recurse!

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

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 …

  • Author

thanks for the help where do i put the  TagA and where?

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

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:

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.

@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

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: [ … ]

 

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.

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

Use

Substitute(yourTextField; ¶ ; ",")

Create an account or sign in to comment

Important Information

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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.