Re: Remove extra spaces from a string
Re: Remove extra spaces from a string
- Subject: Re: Remove extra spaces from a string
- From: julifos <email@hidden>
- Date: Fri, 06 Jun 2003 19:31:14 +0200
>
The Anarhcy lists a content of an FTP server in a file, what looks like
>
this:
>
>
-rwx------ 0 286 512 Jun 06 12:36 demo10.log
>
-rwx------ 0 286 512 Jun 06 12:37 demo11.log
>
-rwx------ 0 286 512 Jun 06 12:38 demo12.log
>
-rwx------ 0 286 512 Jun 06 12:39 demo13.log
>
-rwx------ 0 286 512 Jun 06 12:40 demo14.log
>
>
I have to get the name of the file (last text item of... With a space TID),
>
what works fine, and the creation date of the file. Between the first three
>
columns there are multiple spaces. I get many "" strings, if I do a repeat
>
loop with a space TID. How can I remove the extra spaces in AS or Finder
>
from a string like this? I found a script for it in InDesign, but the
>
application keywords doesn't work anywhere else.
>
>
Thanks!
>
>
--
>
Bye!
>
Matyas Ferenc Farkas
While some folk comes with a better-than-this routine, you can try this
(extracts only date & log name):
########################################
set AnarchyList to "-rwx------ 0 286 512 Jun 06 12:36
demo10.log
-rwx------ 0 286 512 Jun 06 12:37 demo11.log
-rwx------ 0 286 512 Jun 06 12:38 demo12.log
-rwx------ 0 286 512 Jun 06 12:39 demo13.log
-rwx------ 0 286 512 Jun 06 12:40 demo14.log"
set pairList to {}
repeat with i in paragraphs of AnarchyList
set AppleScript's text item delimiters to space
set i to i's text items
set {creationDate, fileName} to {"" & i's items -4 thru -2, i's item -1}
set AppleScript's text item delimiters to {""}
set end of pairList to {creationDate, fileName}
end repeat
pairList --> {{"Jun 06 12:36", "demo10.log"}, {"Jun 06 12:37",
"demo11.log"}, {"Jun 06 12:38", "demo12.log"}, {"Jun 06 12:39",
"demo13.log"}, {"Jun 06 12:40", "demo14.log"}}
########################################
And here, a recursive routine to convert *several spaces* to *single space*:
########################################
set AnarchyList to "-rwx------ 0 286 512 Jun 06 12:36
demo10.log
-rwx------ 0 286 512 Jun 06 12:37 demo11.log
-rwx------ 0 286 512 Jun 06 12:38 demo12.log
-rwx------ 0 286 512 Jun 06 12:39 demo13.log
-rwx------ 0 286 512 Jun 06 12:40 demo14.log"
set removeThis to space & space
set replaceWith to space
repeat while removeThis is in contents of AnarchyList
set AppleScript's text item delimiters to removeThis
set AnarchyList to AnarchyList's text items
set AppleScript's text item delimiters to replaceWith
set AnarchyList to "" & AnarchyList
end repeat
set AppleScript's text item delimiters to {""}
AnarchyList --> "-rwx------ 0 286 512 Jun 06 12:36 demo10.log
-rwx------ 0 286 512 Jun 06 12:37 demo11.log
-rwx------ 0 286 512 Jun 06 12:38 demo12.log
-rwx------ 0 286 512 Jun 06 12:39 demo13.log
-rwx------ 0 286 512 Jun 06 12:40 demo14.log"
########################################
JJ
_______________________________________________
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.