September 14, 20196 yr 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
September 14, 20196 yr 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, 20196 yr by comment
September 15, 20196 yr 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!
September 15, 20196 yr 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 )
September 15, 20196 yr 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 ; ¶ ; " " ) )
Create an account or sign in to comment