• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: read a specific word of a text file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: read a specific word of a text file


  • Subject: Re: read a specific word of a text file
  • From: John Stewart <email@hidden>
  • Date: Thu, 23 Sep 2004 04:15:50 -0400

On 09/23/04 at +0530 Jasneet Kaur said this

>I need to read a specific word of a text file (in Mac's text editor) and
>then replace it with another word.
>
>(that is, the kind of action we do with the "Replace All" option in notepad
>when using windows)
>
>So could you please help me do that using AppleScript


set txtStr to "The text you want to search" -- Original text
set srchStr to "you" -- the word or words to be replaced
set rplcStr to "I" -- the word or words to replace with
my doRplc(txtStr, srchStr, rplcStr)

--> "The text I want to search"

on doRplc(txtStr, srchStr, rplcStr)
    set {oldDelims, AppleScript's text item delimiters} to {AppleScript's text
item delimiters, {srchStr}}
    set temp to every text item of txtStr
    set AppleScript's text item delimiters to {rplcStr}
    set txtStr to temp as text
    set AppleScript's text item delimiters to oldDelims
    return txtStr
end doRpl

JBS
--
If Barbie is so popular, why do you have to buy her friends?
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >read a specific word of a text file (From: Jasneet Kaur <email@hidden>)

  • Prev by Date: Re: read a specific word of a text file
  • Next by Date: Re: How to set the background image of a folder ?
  • Previous by thread: Re: read a specific word of a text file
  • Next by thread: Re: read a specific word of a text file
  • Index(es):
    • Date
    • Thread