realbasic-nug
[Top] [All Lists]

Re: Truncating a string

To: REALbasic Network Users Group <realbasic-nug at lists dot realsoftware dot com>
Subject: Re: Truncating a string
From: Kevin Ballard <kevin at sb dot org>
Date: Sun, 30 Dec 2001 18:40:15 -0500
On 12/30/01 5:56 PM, "Mike Benonis" <mbenonis_lists at mac dot com> wrote:

> Does anyone know of a plugin or toolbox call to truncate a string to a given
> width in pixels?

Use RB code:

Function truncString(str As String, width As Integer, theFont As String,
theSize As Integer) As String
  Dim p As Picture
  Dim s As String
  Dim g As Graphics

  p = NewPicture(1, 1, 1)
  g = p.Graphics
  
  g.TextFont = theFont
  g.TextSize = theSize
  
  s = str
  
  While g.StringWidth(s) > width
    s = Left(s, Len(s) - 1)
  Wend
  
  Return s
End Function

--
Kevin Ballard
kevin at sb dot org
http://kevin.sb.org/



<Prev in Thread] Current Thread [Next in Thread>