• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: adding spaces
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: adding spaces


  • Subject: Re: adding spaces
  • From: Nigel Garvey <email@hidden>
  • Date: Tue, 26 Aug 2003 10:17:43 +0100

Natalie Lambert wrote on Mon, 25 Aug 2003 20:15:09 -0700 (PDT):

>I need to take a piece of data and ensure it is a
>specific character length. If the number of charaters
>are less than those required then I need to fill the
>rest with spaces

>the space the heading needs to fill is 20 characters
>the heading is "Cars"

>I know this is going to need a repeat function but I'm
>a little unclear on the adding spaces bit since I
>haven't scripted in a while.

You don't actually need a repeat here. The simplest way is to concatenate
twenty spaces to the heading and then use the first twenty characters of
the result:

set heading to "Cars"
set heading to text 1 thru 20 of (heading & " ")

If your original heading has more than twenty characters, it will of
course be truncated rather than padded by this method. If you don't want
that to happen, then:

set heading to "Cars"
if (count heading) < 20 then
set heading to text 1 thru 20 of (heading & " ")
end if

NG
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: adding spaces
  • Next by Date: Re: adding spaces
  • Previous by thread: Re: adding spaces
  • Next by thread: Re: adding spaces
  • Index(es):
    • Date
    • Thread