extracting characters from a string

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf extracting characters from a string

  • Creator
    Topic
  • #49010
    Manny Zachodin
    Participant

      I am using in xlate a statement to extract the last 2 characters from a 15 bytes long string by typing TCL code directly in a box “string trimleft mystring 13″. Whatever I do I get back the same long string of 15 bytes. I tried also with ‘trimright” function with no success.  The function ‘tolower’ and toupper” are functioning correctly.  Thanks for your help.

    Viewing 4 reply threads
    • Author
      Replies
      • #60463
        Manny Zachodin
        Participant

          used string range function and it worked for me…still wandering why trimleft did not work…but never mind.  Thanks.

        • #60464

          string trimleft string chars

          If chars is blank, then trimleft defaults to whistespace.

          Example:

          set line1 ”    000011112222″ ;# leading spaces

          set line2 [string trimleft $line1] ;# defaults to whitespace

          Result: “000011112222”

          Example:

          set line1 “aaaabbbbcccddd”

          set line2 [string trimleft $line1 a] ;# removes leading “a” characters

          Result: “bbbbcccddd”

          -- Max Drown (Infor)

        • #60465
          Jim Kosloskey
          Participant

            Manny,

            String trim is for removing leading and/or trailing characters of a certain content (such as zeros, spaces, etc.) not for a number of characters.

            As you determined, string range allows you to pick a certain number of characters regardless of their content.

            Jim Kosloskey

            email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

          • #60466
            Manny Zachodin
            Participant

              Thank you both for your educated input.

            • #60467
              Charlie Bursell
              Participant

                Using the wrong command I guess as you know by now.  ðŸ™‚

                To get the last two characters of a string of any length use the special notation of “end’.  You can do then do math with the end notation.  For example:

                set str ABCDEFG

                set subStr [string range $str end-1 end]

                => FG

            Viewing 4 reply threads
            • The forum ‘Cloverleaf’ is closed to new topics and replies.