Tcl to look at the last occurance of a delimiter

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Tcl to look at the last occurance of a delimiter

  • Creator
    Topic
  • #49948
    Rentian Huang
    Participant

      Greeting Cloverleafers!!!

      Can anyone provide a handy code to look at the last occurance of a delimiter?

      Example:

      Code:

      Fluid-Restricted, 1500 ml-FR1500


      There could be dashes within the description (Fluid-Restricted, 1500 ml) but I always want the last part (FR1500) delimited by “-“.

      Thanks in advance!

      Sam  8)

    Viewing 1 reply thread
    • Author
      Replies
      • #64228
        Michael Hertel
        Participant

          hcitcl>set data “Fluid-Restricted, 1500 ml-FR1500”

          Fluid-Restricted, 1500 ml-FR1500

          hcitcl>echo [lindex [split $data -] end]

          FR1500

          hcitcl>

          If you know what your delimiter is always gonna be, it’s easy.

        • #64229
          Rentian Huang
          Participant

            Exactly what I am looking for, thanks a bunch! I use this

            Code:

            string trim [lindex [split $data -] end]


            to get rid of unexpected spaces too.

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