Author Topic: Elipse text  (Read 2252 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"