Re: Path-Strings to Formatted String
Re: Path-Strings to Formatted String
- Subject: Re: Path-Strings to Formatted String
- From: Kai Edwards <email@hidden>
- Date: Sun, 17 Feb 2002 06:04:27 +0000
on Fri, 15 Feb 2002 13:44:27 -0500, Arthur J Knapp
<email@hidden> wrote:
>
OK, my brain is beginning to hurt, perhaps someone could do all my
>
work for me so I can go home? ;-)
(snip)
>
What I want to achieve is a string in this format:
>
>
"MacHD:
>
Projects:
>
Project 1:
>
Art:
>
CHAP01:
>
CHAP02:
>
Project 2:
>
Art:
>
CHAP01:
>
CHAP02:
>
Old:
>
CHAP01:
>
CHAP02:
>
"
>
>
where each indentation level is preceded by an appropriate
>
number of tabs.
>
>
After several hours of playing with this, I've come to
>
realize that it is a lot harder than it looks to accomplish
>
this, as it seems to require several nested repeat loops
>
and a lot of maintaining of "state", or really complex
>
recursion that I just can't seem to work out the details of.
I was intrigued by this problem, so I've just been playing with a few loops.
One question that occurred to me was how to deal with variable nesting - so
I tried to build in a device to cope with this. (This may not be an issue of
course.)
In addition, since I couldn't get your initial list (as posted) to compile,
I treated it as a normal list. Was this what you intended?
Anyway, it may be riddled with faults (and I *know* my variable names are a
mess). But I thought I'd throw it over to you raw, anyhow - warts'n'all!
(Since I'm still learning this game, I thought I'd better leave all the
clever stuff to you) ;)
---------------------------------------------------------------
set oldList to {"MacHD:Projects:Project 1:Art:CHAP01:",
"MacHD:Projects:Project 1:Art:CHAP02:", "MacHD:Projects:Project
2:Art:CHAP01:", "MacHD:Projects:Project 2:Art:CHAP02:",
"MacHD:Projects:Project 2:Old:CHAP01:test:", "MacHD:Projects:Project
2:Old:CHAP02:"}
set {reset, store, lastCount, newList, text item delimiters} to
[NO BREAK]{true, {}, 0, "", ":"}
repeat with stage in oldList
set iList to (stage as string)'s text items 1 thru -2
set iCount to count iList
repeat with i from 1 to iCount
set {iLevel, addOn} to {iList's item i, i > lastCount}
if reset or iLevel item i of store or addOn then
if reset then
set store's end to iLevel
else
set {store, reset} to {iList, true}
end if
set tabs to ""
repeat with t from 2 to i
set tabs to tabs & tab
end repeat
set newList to newList & tabs & iLevel & ":" & return
end if
end repeat
if reset then set reset to false
set lastCount to iCount
end repeat
set text item delimiters to {""}
text 1 thru -2 of newList
---------------------------------------------------------------
I hope at least some of it works OK!
Kai
--
**********************************
Kai Edwards Creative Resources
1 Compton Avenue Brighton UK
Telephone +44 (0)1273 326810
**********************************
_______________________________________________
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.