Sorting search results - solution needed

Scott Seward scott at copware.com
Thu Oct 25 12:43:12 EDT 2018


Hey guys, thanks for all the possible solutions. I'm sure somewhere in here I'll get it to do what I need. Special thanks to those that wrote code. Much appreciate it!

Scott

On 10/24/18, 1:28 PM, "use-livecode on behalf of Niggemann, Bernd via use-livecode" <use-livecode-bounces at lists.runrev.com on behalf of use-livecode at lists.runrev.com> wrote:

    here is my take, clumsy and not respecting all formatting requirements
    
    Instead of
    
    187.1
    187.1.1
    187.1.2
    187.3
    187.22
    187.33
    187.234
    
    it sorts
    
    187.1
    187.1.1
    187.1.2
    187.22
    187.234
    187.3
    187.33
    
    Kind regards
    Bernd
    
    
    
    
    -----------------------------------------------
    on mouseUp
       put field "fAlpha" into tData
       put "" into msg
       sort tData numeric by specialSort(each) 
       put tData into field "fSort"
    end mouseUp
    
    function specialSort pEach
       put pEach into tData
       --put word 1 to -1 of tData into tData
       put "0,1,2,3,4,5,6,7,8,9,." into tNumbers
       
       -- check for double colon like in 187.1.2
       put 0 into tSkip
       put 0 into tCounter
       repeat
          put offset(".", tData, tSkip) into tOffset
          if tOffset > 0 then
             add tOffset to tSkip
             add 1 to tCounter
          else
             exit repeat
          end if
       end repeat
       if tCounter > 1 then 
          --put tData && tCounter & cr after msg
          put empty into char tSkip of tData
          return tData
       end if
       
       repeat with i = 1 to the number of chars of tData
          if char i of tData is among the items of tNumbers then 
             put char i of tData after tNumberPart
          else
             exit repeat
          end if
       end repeat
       
       
       if tData = tNumberPart then
          return tNumberPart
       end if
       
       put length(tNumberPart) into tLength
       put char tLength + 1 to - 1 of tData into tRest
       if char tLength of tNumberPart = "." then put "." before tRest
       
       replace ")" with empty in tRest
       replace space with empty in tRest
       
       put toUpper(tRest) into tRest
       
       put true into tLeftBracket
       put 0 into tDecimal
       repeat with i = 1 to the number of chars of tRest
          
          put char i of tRest into tChar
          
          if tChar is a Number then
             add  tChar * .00001 to tDecimal
             
          else if tChar is "(" then
             if tLeftBracket then
                add .0000001 to tDecimal
                put false into tLeftBracket
             end if
             
          else if tChar is "." then -- ASCII "." = 46
             add .00001 to tDecimal
             
          else if charToNum(tChar) >= 65 then -- ASCII "A" = 65
             add (charToNum(tChar)-64) * .00009 to tDecimal
          end if
       end repeat
       
       return tNumberPart + tDecimal
    end specialSort
    -----------------------------------------------------
    
    _______________________________________________
    use-livecode mailing list
    use-livecode at lists.runrev.com
    Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
    http://lists.runrev.com/mailman/listinfo/use-livecode
    



More information about the use-livecode mailing list