Jump to content

Mutiple break calculation


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

Recommended Posts

Quick Quesstion, I have a number that I want to be formatted automatically upon entry to keep everything the same. The number is 11 characters and broken up as 2,3,3,3 or eg 11 111 111 111. Now I have used a calculation 

Let(
@NumbersOnly = Filter(Self; "0123456789");

Case(

Length(@NumbersOnly) = 10;

"("&""&

Left (@NumbersOnly; 2) &")"& "" &" "&


Middle(@NumbersOnly;3;4) & "-" &


Right (@NumbersOnly;4)

))

to format a phone number specifically and that is fine. But for the love of Mike how would I break up thea bove example to the 11 111 111 111 format when enterd as 11111111111

Link to comment
Share on other sites

Here's one way:

Let (
digits = Filter ( Self ; "0123456789" )
;
Left ( digits ; 2 ) & " " & Middle ( digits ; 3 ; 3 ) & " " & Middle ( digits ; 6 ; 3 ) & " " & Right  ( digits ; 3 )
)

Here's another:

Let (
digits = Filter ( Self ; "0123456789" ) 
;
Replace ( Replace (  Replace ( 
digits ; 
9 ; 0 ; " " ) ;
6 ; 0 ; " " ) ;
3 ; 0 ; " " )
)

I did not test for length, because you didn't say what should be done when the test fails. In your example, the entry would have been erased - which is kind of cruel to the user.

  • Like 1
Link to comment
Share on other sites

Thanks Comment, I have a cruel streak :) Not really! I hadn't Picked up on that so will look but I will try your suggestion. I guess I wasn't sure how to deal with the 2 middle arguments. I wasnt sure if you could only have 1 instance but from your suggestion it appears that you can "nest" them for want of a better word. Thanks for your help as usual always prompt.

Link to comment
Share on other sites

You can concatenate as many Middle() function calls as you need. The name Middle does not refer to your calculation; it refers to the string from which the function will extract a "middle" part  (unlike the Left() or Right() functions, which will only extract a part from one of the string's ends).

 

Edited by comment
Link to comment
Share on other sites

10 hours ago, comment said:

Here's another:

Let (
digits = Filter ( Self ; "0123456789" ) 
;
Replace ( Replace (  Replace ( 
digits ; 
9 ; 0 ; " " ) ;
6 ; 0 ; " " ) ;
3 ; 0 ; " " )
)

 

Nice use of Replace()  !!!!  :-)

Link to comment
Share on other sites

This topic is 2270 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
 Share

×
×
  • Create New...

Important Information

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