BASIC

Author Topic: Elipse text  (Read 2107 times)

MrTAToad

  • Guest
Elipse text
« on: 2010-Feb-20 »
If you have a great big long bit of text that needs displaying (for example a long filename), but it wont fit into a certain space, the best way is to display the first and last few characters, with this routine :

Code: GLBasic [Select]
FUNCTION elipseText$:text$,maxLength%=15
LOCAL pos%,lft%
LOCAL l$,r$,m$

        IF LEN(text$)>maxLength%*2
                pos%=INSTR(text$,".")
                lft%=LEN(text$)-pos%

                l$=MID$(text$,0,maxLength%)
                r$=MID$(text$,pos%-maxLength%)
                m$=MID$(r$,0,LEN(r$)-lft%)

                RETURN l$+"..."+m$+MID$(text$,pos%)
        ELSE
                RETURN text$
        ENDIF

ENDFUNCTION
 

Example :
Code: GLBasic [Select]
DEBUG "Elipse text : "+elipseText$("Hellothisfilehasmorethan30charactersandthisfayl.exe")+"\n"