Re: Remove extra spaces from a string
Re: Remove extra spaces from a string
- Subject: Re: Remove extra spaces from a string
- From: John Delacour <email@hidden>
- Date: Sun, 8 Jun 2003 09:48:52 +0100
- Mac-eudora-version: 6.0b20
If you must use Applescript, then it's quicker and neater to use 'offset' :
set s 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 ls to {}
set my text item delimiters to ""
repeat with p in paragraphs of s
set oset to -1 * (offset of " " in ("" & reverse of characters of p))
set my text item delimiters to space
set t to text oset through -1 of p
set df to text item 3 of t & space & text item 4 of t
set df to df & ", " & last text item of t
set my text item delimiters to ""
set end of ls to df
end repeat
ls
At 9:57 am +0200 8/6/03, Jean-Baptiste LE STANG wrote:
An d of course a home made Applescript will work too. you can
eihter choose to do it recursively or not, and can pass a list of
string too. No as quick as other methods.
JB
<script>
on replace(inThisString, thisMatch, byThisString, recursively)
if class of inThisString is list then
repeat with x from 1 to count inThisString
set item x of inThisString to replace(item x of
inThisString, thisMatch, byThisString, recursively)
end repeat
return inThisString
else
set finalString to inThisString
set oldTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to thisMatch
set myTextItems to get every text item of finalString
set finalTextItemsList to {}
repeat with x from 1 to count myTextItems
if item x of myTextItems is not "" then set end of
finalTextItemsList to item x of myTextItems
end repeat
set AppleScript's text item delimiters to byThisString
set finalString to finalTextItemsList as string
if ((count (finalTextItemsList)) is not 1 and recursively)
then set finalString to replace(finalString, thisMatch,
byThisString, recursively)
set AppleScript's text item delimiters to oldTID
return finalString
end if
end replace
<script>
_______________________________________________
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.