8 Replies Latest reply on Mar 19, 2015 4:41 AM by siplus

    Split text

    malachydevlin

      Hi, I know this should be bread and butter but I cant remember how to split this field so that everything before the " : " goes to 1 field and everything after to another.

      field:

      ASD:234

      A:23

       

      they are all carrying lengths.

        • 1. Re: Split text
          nicolai

          Left ( "ASD:234" ; Position ( "ASD:234" ; ":" ; 1 ; 1 )-1 )

           

          Right ( "ASD:234" ; length("ASD:234") -  Position ( "ASD:234" ; ":" ; 1 ; 1 ))

          • 2. Re: Split text
            nicolai

            Wrapping into let, just swap leftValue and rightValue

             

            Let (
                 [
                      myString = "ASD:234";
                      leftValue =Left ( myString ; Position ( myString ; ":" ; 1 ; 1 )-1 );
                      rightValue=Right (myString ; length(myString) -  Position ( myString ; ":" ; 1 ; 1 ))
                 ]
            ;
                 leftValue
            )
            
            • 3. Re: Split text
              nicolai

              An alternative:

               

              Let (
                   [
                        myString = "ASD:234";
                        myString = Substitute ( myString ; ":" ; " " );
                        leftValue =LeftWords ( myString ; 1 );
                        rightValue=RightWords ( myString ; 1 )
                   ]
              ; 
                    rightValue
               )
              

               

               

              or 

               

              LeftWords ( Substitute ( "ASD:234" ; ":" ; " "),1)

               

              RightWords ( Substitute ( "ASD:234" ; ":" ; " "),1)

              • 4. Re: Split text
                malachydevlin

                Thanks again for your help, worked a treat.

                I added a patterncount also to make sure the ":" existed, some had no split..

                thanks a lot..

                • 5. Re: Split text
                  siplus

                  Yet another one:



                  when myString = "ASD:234"


                  Then


                  $Split = Substitute(mystring;":";¶)


                  so


                  Field1 = GetValue($Split;1)  and Field2 = GetValue($Split;2)


                   

                  • 6. Re: Split text
                    beverly

                    Yep! I use the old make-my-stirng-a-list trick (change the 'delimiter' to returns) when I am absolutely sure the content does not contain the return.

                     

                    If

                    ( patterncount ( myString ; ¶ ) ; ... // use the left, right and middle with patterncount & position functions

                    ; ... // use the substitute and getValue functions

                    )

                    • 7. Re: Split text
                      user19752

                      Appending delimiter makes it a bit simple?

                       

                      lefts

                      Let ( str = field & ":" ; Left ( str ; Position ( str ; ":" ; 1 ; 1 ) - 1 ) )

                      rights

                      Replace ( str ; 1 ; Length ( lefts ) + 1 ; "" )

                      • 8. Re: Split text
                        siplus

                        readability counts, in my book