lsearch and spaces

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf lsearch and spaces

  • Creator
    Topic
  • #53062
    Johnny Anderson
    Participant

      CL v5.8, HL7 v2.3.1, Sun, Solaris 10

      In a tclproc, I have this lsearch working: set index1 [lsearch -regexp $list1 $pattern1], but only when there are no spaces in $list1 and $pattern1.

      I can remove all spaces from both and then get a match but I’d rather know if there’s a way to include spaces in both.

      Example: I want $list1 line “abc  xyz” to match $pattern1 line “abc  xyz”.

      I’ve searched the forum and manuals but can’t find anything about spaces.

    Viewing 2 reply threads
    • Author
      Replies
      • #76413
        Charlie Bursell
        Participant

          lsearch tests against list elements.  If you have a single list element that contains “abc xyz” then yout pattern should match.  But not if abc and xyz are different elements of a list.

          For example

          set list1

            lsearch -regexp $list1 {abc xyz}

            => 0

            Of course you could have used -exact instead of -regexp

        • #76414
          James Cobane
          Participant

            Johnny,

            Any list element that contains spaces must be enclosed in curly braces to be treated as a single element; spaces are considered list element separators, so if list1 is “abc xyz 123” and not “{abc xyz} 123”, it will essentially be a list with 3 elements, not 2.

            i.e.

            set list1

              set pattern1 “abc xyz”

              lsearch -regexp $list1 $pattern1

              Hope this helps.

              Jim Cobane

              Henry Ford Health

          • #76415
            Johnny Anderson
            Participant

              Charlie, James, thanks.  Its working now.

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