RE: deleting text
RE: deleting text
- Subject: RE: deleting text
- From: "Ruby Madraswala" <email@hidden>
- Date: Wed, 26 Nov 2003 09:24:31 -0500
- Thread-topic: deleting text
Thanks Kai, I was able to take couple of lines out of my code. Once the deleting slash and pipe worked, I decided to delete some more special characters, and I had it searching and replacing one character at a time.
Now that I have deleting working, do I use the same concept to add any special characters to a word?
Ruby
-----Original Message-----
From: email@hidden [
mailto:email@hidden] On Behalf Of kai
Sent: Tuesday, November 25, 2003 5:05 PM
To: email@hidden
Subject: Re: deleting text
on Tue, 25 Nov 2003 13:51:09 -0500, "Ruby Madraswala" wrote:
>
I am having problem with a simple script..........................
>
* I have text files (over 60 to 200 paragraphs).
* I am trying to write a script
to delete the "\" always in front of a word and "|" (pipe) at end of a word. "\" and "|" can be at beginning and end of one word. Sounds simple but I can't get the delete statement to work. What am I missing here and am I using the wrong command and or wrong approach. (trying with the slash first). Can tell I am a beginner at scripting.
>
>
Set NewFile to Pathname
>
On deleteslash
>
Set outfile to open access file NewFile with write permission
>
Set File1Text to read outfile from 1
>
Set wordlist to every word of File1Text
>
Repeat with aword in wordlist
>
Display dialog aword - to debug
>
If aword contains "\\" then
>
Display dialog aword -to debug
>
Delete character 1 of aword
>
End if
>
End repeat
>
Close access outfile
>
Return
>
End deleteslash
>
>
Sample text file:
>
Debugging - this isn't \removing| illegal listening devices from your office.
It's \tracking down and fixing| script problems.
There's no specific 'delete' command that I'm aware of, Ruby - although there are other ways of removing items of text.
Given the file size that you're talking about, I'd be tempted to try reading the entire contents of each file, manipulating it all in AS - and then writing it back to the file.
The following example is (like me) about as simple as they come - although it comes with a couple of caveats: Firstly, it will delete *every* occurrence of the character(s) specified. In addition, if the text in the file has numerous (thousands of) occurrences of a particular 'delete' character, then you may get a 'stack overflow' error. (There are ways around both issues, so yell if you need more help.)
Anyway, this might help to get you started:
-----------------------
set f to "path:to:file"-amend as appropriate
set t to read f
repeat with x in {"\\", "|"}
set text item delimiters to x
set t to t's text items
set text item delimiters to ""
set t to t as string
end repeat
set eof f to 0
write t to f
-----------------------
---
kai
_______________________________________________
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.