Two blanks in a row, TCL help

Homepage Clovertech Forums Cloverleaf Two blanks in a row, TCL help

  • Creator
    Topic
  • #111015
    Jason Puskar
    Participant

    Hello,

     

    I have a simple problem but not able to figure out. I have an issue where I am passing an address line to a xlate tcl. The TCL reads in each work and turns it to proper case with tupper/tolower commands. All this works fine, but some of the address fields have two blanks between the street and the second address line.  The TCL returns the double brackets {} for the blank instead. What simple thing am I overlooking that will remove double spaces?

     

     

    Outbound message

    ||950 Calcon Hook Road {} Suite 15^^Sharon Hill^PA^19079^^O||

     

    Tcl code

    }

    set inList [lindex $xlateInVals 0]

    set inListSplit [split $inList ” “]

    foreach item $inListSplit {

    set item [string tolower $item 1 end]

    set item [string toupper $item 0 0]

    set xOut [lappend xOut $item]

     

    }

     

     

    set xlateOutVals

    Viewing 5 reply threads
    • Author
      Replies
      • #111016
        David Barr
        Participant

        Try replacing your “split” line with this:

        set inListSplit [regexp inline all {\S+} $inList]

        Split always returns empty elements if you have consecutive separator characters.

      • #111017
        Jim Kosloskey
        Participant

        Or maybe do a string map to change 2 spaces to one space before doing the split.

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

      • #111018
        Tim Pancost
        Participant

        When you split a string that contains two spaces adjacent to each other, it’s going to create an empty element in the resulting list.  So when you loop through that list, the empty element is one of the iterations that just gets tacked onto your ending list.  You could add an ‘if’ to check the length of the element and only do your string operations if the length of the element is greater than zero.  Your result will not have the extra space in it, though, like the original string.

        If you want to keep the extra space, you could try something like the following.  Basically treats the address line as a “sentence”, and uses “string totitle” to capitalize the first letter in each word in the sentence.

        set inList [lindex $xlateInVals 0]

        set address [subst [regsub -all {\S+} $inList {[string totitle &]}]]

        set xOut

           

          HTH,

          TIM

          Tim Pancost
          Trinity Health

        1. #111019
          Jason Puskar
          Participant

          Jim,

          I like the string map idea and tried it myself.  I must not have the right syntax.  How would you code it?

        2. #111020
          Jim Kosloskey
          Participant

          I think I would try:

          string map {{  } { }} variable

          where the first element has 2 spaces between { and }, the second element has a single space between { and }.

           

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

        3. #111044
          Jason Puskar
          Participant

          All,

          Thanks again for the help and coding suggestions.  As it worked out for us, we don’t need the blank space so I used the method to only copy over the fields when the length is > then 0.

          Jay

      Viewing 5 reply threads
      • You must be logged in to reply to this topic.

      Forum Statistics

      Registered Users
      5,117
      Forums
      28
      Topics
      9,292
      Replies
      34,432
      Topic Tags
      286
      Empty Topic Tags
      10