Simple IF on length

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Simple IF on length

  • Creator
    Topic
  • #54190
    Tim Pashon
    Participant

      I’m trying to see if a string is shorter than a certain length and nothing is working.

      I get the length of the string and store it, but when I compare, it’s not giving me the correct answer.

      In a preproc, I have “set xlateOutVals [string length $xlateInVals]”

      I put the length in @lgth and when I use an IF statement after that, the desired results are happening.

      Anyone?

    Viewing 2 reply threads
    • Author
      Replies
      • #80493
        bill bearden
        Participant

          First, you should treat xlateInVals and xlateOutvals as lists. It is possibly not your issue but, if I didn’t say it, someone else surely would have. So…

          set xlateOutVals

            ]]

            Another thing to check out is which operator you are using in your IF when you get back to the xlate logic. Are you using the string comparison (ge) or are you using the numeric comparison (>=)? I get what I think you are looking for when I use >=, as in:  @lgth  >= =5

          1. #80494
            Femina Jaffer
            Participant

              How about something like this:

              set len [string length $xlateInVals]

              if {$len == 10} {

                  set data “”

                  set xlateOutVals $data    

                }

              }

            • #80495
              Charlie Bursell
              Participant

                Harping on the same old subject that xlateInVals and xlateOutVals are lists!

                If there happens to be a space in the value the command [string length $xlateInVals] will return the wrong value since it will be quoted like:

                {String With Space}

                The correct syntax would be  set len [string length [lindex $xlateInVals 0]]

                Also the list paradigm needs to be applied to xlateOutVals

                I think Bill has it right

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