splitting field

Clovertech Forums Read Only Archives Cloverleaf Tcl Library splitting field

  • Creator
    Topic
  • #52154
    Kevin Crist
    Participant

      i am trying to split a field V99999-1-1234567891. What i want is the V99999-1. but splitting on the ” – ” using a 0 i get V99999, using a 1 i get 1 and using a 2 i get 1234567891. How do just keep the V99999-1 part?

      Thanks for any ideas.

    Viewing 3 reply threads
    • Author
      Replies
      • #73239
        Rob Abbott
        Keymaster

          try this, assume “field” has the data and “result” will contain the stuff you want to keep;

          set result [join [lrange [split $field -] 0 1] -]

          Rob Abbott
          Cloverleaf Emeritus

        • #73240

          This might work, too.

          set value “”

          regexp ^(.*?-.) $value match newValue

          puts $newValue

          Or something along those lines depending on exactly what you want to capture.

          Also, maybe something as simple as string range may give you what you need?

          -- Max Drown (Infor)

        • #73241
          Robert Kersemakers
          Participant

            Many roads… Another one that works:

            set result [string range $field 0 [expr [string last “-” $a]-1]]

            Zuyderland Medisch Centrum; Heerlen/Sittard; The Netherlands

          • #73242
            Kevin Crist
            Participant

              all work. Thanks a bunch gentleman.

          Viewing 3 reply threads
          • The forum ‘Tcl Library’ is closed to new topics and replies.