Re: tabs to spaces
Re: tabs to spaces
- Subject: Re: tabs to spaces
- From: "Mark J. Reed" <email@hidden>
- Date: Mon, 1 Dec 2008 23:46:09 -0500
On Mon, Dec 1, 2008 at 7:55 PM, Scott Haneda <email@hidden> >
Something like this:
>
> dasdaads dasdas dasdas das
> ds dsd dasd dsad dd ds
>
> Lets call the above data my_data
>
> set lines to {}
> set lines to paragraphs of my_data
You don't need the first "set". Just
set lines to paragraphs of my_data
will create the lines variable.
> So, that will get me a list where each line is a list element?
> Something like this: {line1, line2} ?
Yes.
> If I then wanted to iterate though the lines and convert each tab seperated
> chunk to a list as well
> repeat with a_line in lines
> -- What do i do here?
> -- I think this is it, but it is not working well for me
> set AppleScript's text item delimiters to tab
> set cells to text items of a_line
> set text item delimiters to ""
> end repeat
OK, you're creating a list of fields for each line, but you're not
storing them anywhere permanent - the "cells" variable is overwritten
each time.
There's no need to set and reset the text item delimiters (TID) each
time through the loop, either.
set oldTID to text item delimiters -- don't assume you know what they are
set text item delimiters to tab
set rows to {} -- need this one since we're appending later
repeat with a_line in lines
set cells to text items of a_line
set end of rows to cells
end repeat
set text item delimiters to oldTID
rows
The "set end of rows" is the key - that appends a new element to the
"rows" list, which is itself a list of fields. You could also do it
in one swell foop
without the "cells" variable:
set end of rows to text items of a_line
> From there, is there a way to split() in AS, or suggestion on simply way to
> go back to \r separated lines, with a single space between each item of the
> words in the list.
I think you mean join(), but yes, text item delimiters work both ways.
If you do
some_list as text
you get back the elements of the list joined by the current value of
the text item delimiters. So:
set text item delimiters to space
set out_lines to {}
repeat with row in rows
set end of out_lines to row as text
end repeat
set text item delimiters to return
out_lines as text
> Also, is there way to return the clipboard with a style attribute, such as
> setting it to Monaco?
Yes, but I don't know it. :) I used to, but that mechanism has been
deprecated, and I haven't used the new one. I'm sure someone else can
help you there, though.
--
Mark J. Reed <email@hidden>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden