john9210 Posted September 14, 2019 Posted September 14, 2019 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
comment Posted September 14, 2019 Posted September 14, 2019 (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 September 16, 2019 by comment 1
Steve Martino Posted September 15, 2019 Posted September 15, 2019 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!
comment Posted September 15, 2019 Posted September 15, 2019 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 ) 1
comment Posted September 15, 2019 Posted September 15, 2019 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 ; ¶ ; " " ) ) 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now