• 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: "Bob.Kalbaugh" <email@hidden>
  • Date: Tue, 26 Aug 2003 00:12:34 -0500

on 8/25/03 10:15 PM, Natalie Lambert at email@hidden wrote:

> I'm finding lots of references on triming spaces but
> nothing on adding spaces...
>
> 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
>
> ie
>
> the space the heading needs to fill is 20 characters
> the heading is "Cars"
>
> the script needs to:
> set x to count characters of heading
> subtract x from 20
> add one space for the remainder
> --in this case cars + 16 spaces
>
> 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.
>
> can anyone help?
>
> thanks
> natalie


I'm sure you'll get many examples. Here is one way. It does not use a repeat
function, just simple math.

----
set h to "cars"

set nH to padHeading(h)

on padHeading(x)
set pad to " " -- that's 20 spaces
set headCount to length of x
set y to ((length of pad) - headCount)
set x to (x & (characters 1 thru y) of pad)
return x
end padHeading
----

Hope that helps.

--
Bob.Kalbaugh
_______________________________________________
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.

  • Follow-Ups:
    • Re: adding spaces
      • From: email@hidden (michael.slomski)
References: 
 >adding spaces (From: Natalie Lambert <email@hidden>)

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