8 Replies Latest reply on Apr 29, 2010 8:52 AM by comment_1

    How to configure the text

    stellq

      Title

      How to configure the text

      Post

      The longth of text can not longer than 15.

       

      And the i want to delete () and the content in (), And [] and the content in []

       

      How to achieve this?

       

      Thanks for your answer!!:smileywink:

        • 1. Re: How to configure the text
          arnoldkegebein

          Create a custom function like this:

          Function: LimitText( _text )Let( [
              _p0 = Position( _text; "("; 1; 1 );
              _p1 = Position( _text; ")"; _p0; 1 );
              _text = If( _p0 > 0 and _p1 > _p0;
                      Substitute( _text; Middle( _text; _p0; _p1 - _p0 + 1 ); "" );
                  // Else
                      Substitute( _text; [ "("; "" ]; [ ")"; "" ] )
                  );
              _p0 = Position( _text; "["; 1; 1 );
              _p1 = Position( _text; "]"; _p0; 1 );
              _text = If( _p0 > 0 and _p1 > _p0;
                      Substitute( _text; Middle( _text; _p0; _p1 - _p0 + 1 ); "" );
                  // Else
                      Substitute( _text; [ "["; "" ]; [ "]"; "" ] )
                  )
          ];
              If( Position( _text; "("; 1; 1 ) > 1 or Position( _text; ")"; 1; 1 ) > 1 or Position( _text; "["; 1; 1 ) > 1 or Position( _text; "]"; 1; 1 ) > 1;
                  LimitText( _text );
              // Else
                  Left( _text; 15 )
              )
          )

           

          Test:

          • LimitText( "Hello (your name)" ) --> "Hello "
          • LimitText( "My name is [my name]." ) --> "My name is ."
          • LimitText( "1234(long text)567890(very long text)1234567[very, very long]890" ) --> "123456789012345"

          If brackets overlap or are inside each other, the result might be different than you expect:

          • LimitText( "abc(def[123)456]890" ) --> "abc456890"
          • LimitText( "+(-(#)-)+" ) --> "+-)+" --> "+-+"











          • 2. Re: How to configure the text
            comment_1

            How about =

             

            Trim ( Evaluate ( Substitute (
            Quote ( Text ) ;
            [ "(" ; Quote ( " & /*" ) ] ; [ "[" ; Quote ( " & /*" ) ] ;
            [ ")" ; Quote ( " */ " ) ] ; [ "]" ; Quote ( " */ " ) ]
            ) ) )

            • 3. Re: How to configure the text
              arnoldkegebein

               


              comment wrote:

              How about =

               

              Trim ( Evaluate ( Substitute (
              Quote ( Text ) ;
              [ "(" ; Quote ( " & /*" ) ] ; [ "[" ; Quote ( " & /*" ) ] ;
              [ ")" ; Quote ( " */ " ) ] ; [ "]" ; Quote ( " */ " ) ]
              ) ) )


              This is a nice little trick. I did not know that you can cascade comments: /* /* */ */

               

              But your solution requires brackets in proper pairs. A text like "(xx[xx)" or ":-(" will break the function with an error message: "This comment is not properly terminated."

               

               



              • 4. Re: How to configure the text
                stellq

                Thank you very much!!

                 

                It works very well!!

                 

                :smileyvery-happy:

                 

                If I want to remove the content between ""; how to change the code?

                 

                Waiting for your answer!

                • 5. Re: How to configure the text
                  stellq

                  Works very well !!!!

                   

                  Thanks a lot !!!

                   

                  Can I ask you one more question, if I want to delete the content in "" and "", how to change this code!

                   

                  Thanks for your answer

                   

                  :smileyvery-happy:

                  • 6. Re: How to configure the text
                    arnoldkegebein

                    You have to 'escape' the quote in the function text: \"

                    And adjust the start position to find the second quote: _p0 + 1

                     

                    Function: Limittext( _text )

                    Let( [
                        _p0 = Position( _text; "\""; 1; 1 );
                        _p1 = Position( _text; "\""; _p0 + 1; 1 );
                        _text = If( _p0 > 0 and _p1 > _p0;
                                Substitute( _text; Middle( _text; _p0; _p1 - _p0 + 1 ); "" );
                            // Else
                                Substitute( _text; "\""; "" )
                            );
                        _p0 = Position( _text; "("; 1; 1 );
                        _p1 = Position( _text; ")"; _p0; 1 );
                        _text = If( _p0 > 0 and _p1 > _p0;
                                Substitute( _text; Middle( _text; _p0; _p1 - _p0 + 1 ); "" );
                            // Else
                                Substitute( _text; [ "("; "" ]; [ ")"; "" ] )
                            );
                        _p0 = Position( _text; "["; 1; 1 );
                        _p1 = Position( _text; "]"; _p0; 1 );
                        _text = If( _p0 > 0 and _p1 > _p0;
                                Substitute( _text; Middle( _text; _p0; _p1 - _p0 + 1 ); "" );
                            // Else
                                Substitute( _text; [ "["; "" ]; [ "]"; "" ] )
                            )
                    ];
                        If( Position( _text; "("; 1; 1 ) > 1 or Position( _text; ")"; 1; 1 ) > 1
                            or Position( _text; "["; 1; 1 ) > 1 or Position( _text; "]"; 1; 1 ) > 1
                            or Position( _text; "\""; 1; 1 ) > 1;
                            LimitText( _text );
                        // Else
                            Left( _text; 15 )
                        )
                    )














                    • 7. Re: How to configure the text
                      stellq

                      Thank you thank you thank you !!!!!!!

                       

                       

                      :smileyvery-happy:

                       

                       

                      • 8. Re: How to configure the text
                        comment_1

                         


                        AKegebein wrote:

                        your solution requires brackets in proper pairs. A text like "(xx[xx)" or ":-(" will break the function with an error message: "This comment is not properly terminated."


                         

                        True - and I believe an error is the correct result in such case.