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

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

Recommended Posts

Posted

I'm looking for a field calculation that will break a number into groups of 4 digits, each group separated by a space. The number can have 5 or more digits (say up to 16). For example:

XXXXXXXXXXXXXXXX  to  XXXX XXXX XXXX XXXX

Posted (edited)

Strictly speaking, this is a looping calculation and requires either a recursive custom function or the While() function. However, if the input is limited to 16 digits or less, you could settle for a simple:

Trim ( 
Left ( Yourfield ; 4 )
& " " &
Middle ( Yourfield ; 5 ; 4 )
& " " &
Middle ( Yourfield ; 9 ; 4 )
& " " &
Middle ( Yourfield ; 13 ; 4 )
)

or, if you prefer:

Trim ( 
Replace ( Replace ( Replace (
Yourfield ; 
13 ; 0 ; " " ) ;
9 ; 0 ; " " ) ;
5 ; 0 ; " " )
)

This is assuming that the grouping should start from left - so that an input of 1234567890 will return "1234 5678 90".

 

Edited by comment
  • Like 1
Posted

Genius on the 'Replace' (well to me.  To you it's just another day :) )

How would it look with the While ( ) function?

Just curious.

Thanks!

Posted
1 hour ago, Steve Martino said:

Genius on the 'Replace' (well to me.  To you it's just another day :) )

Actually, I stole it from here:
https://fmforums.com/topic/32095-how-to-format-a-numerical-field-to-show-as-smpte/?do=findComment&comment=145473

 

 

1 hour ago, Steve Martino said:

How would it look with the While ( ) function?

It could be =

While ( [ 
text = Yourfield ; 
start = 5
] ; 
start ≤ Length ( text ) ; 
[ 
text = Replace ( text ; start ; 0 ; " " ) ;
start = start + 5
] ; 
text 
)

 

  • Like 1
Posted

Here's another option, perhaps a more intuitive one:

While ( [ 
text = Yourfield ; 
result = "" 
] ; 
not IsEmpty ( text ) ; 
[ 
result = List ( result ; Left ( text ; 4 ) ) ; 
text = Right ( text ; Length ( text ) - 4 ) 
] ; 
Substitute ( result ; ¶ ; " " )
)

 

  • Like 1

This topic is 1907 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.