2016-09-20 2 views
0

애플 스크립트를 작성하여 .txt 파일의 일부 텍스트를 구문 분석하고 별도의 .txt 파일로 출력하는 데 도움이 될 수 있습니다. 1) 섹션을 식별하고 ("»="), 2) 특정 문자 세트가 섹션에 있는지 확인합니다. "[*]", 3) 특정 섹션이 포함 된 섹션을 모두 인쇄하십시오. 문자 세트, 4) 파일 끝까지 반복하십시오. 기본적으로 이들은 작업 항목이있는 메모이며 열린 작업 항목이 들어있는 메모를 추출하려고합니다. NOTES.TXT에서어플 텍스트로 텍스트 파싱

입력 텍스트의 구조는 다음과 같습니다

»=============================== 

<Date> 2016-09-19 
<Topic> The topic of the day 
<Attendees> Mario, Luigi 

»1) Where to go from here 
- Someone said this 
    [*] Mario: schedule this meeting 
- And who wants to do that other thing? 

»3) So on and so forth [*] Luigi can order the pizza 
»=============================== 

어쩌면 나는 이것에 약간의 도움을받을 수 있습니다 다음과 같이 actionItems.txt에

»=============================== 

<Date> 2016-09-19 
<Topic> The topic of the day 
<Attendees> Mario, Luigi 

»1) Where to go from here 
- Someone said this 
    [*] Mario: schedule this meeting 
- And who wants to do that other thing? 

»2) And on to the next thing 

»3) So on and so forth [*] Luigi can order the pizza 
»=============================== 

<Date> 2016-09-18 
<Topic> The topic of the yesterday 
<Attendees> Zelda, Wario, Snoop Dog 

»1) Where we went from there 
- Who said this 
    [x] Mario: scheduled this meeting yesterday 
- And who wants to do that other thing? 

»2) And on to the next thing again 

»3) So on and so forth * Luigi can order the sausages 
»=============================== 

출력 텍스트가되어야 하는가? 감사!

답변

0

읽기 및 텍스트 파일을 작성하는 것은 AppleScript를 함께 매우 쉽습니다 :

읽기 :

set newFile to ((path to desktop) as string) & "actionItems.txt" 
try 
    open for access file newFile with write permission 
    write (newText & return) to file newFile starting at eof 
    close access file newFile 
on error 
try 
    close access file newFile 
end try 
end try 
: 바탕 화면에 '액션 items.txt'파일에 텍스트 변수를 newText의

set myFile to choose file "Select your txt file" -- ask user to select txt file 
set myText to (read myFile) as string -- content the text file is in variable myText 

쓰기 내용

사이에 강력한 '항목 텍스트 구분 기호'를 사용하여 텍스트를 분할해야합니다. 먼저 같은 구분 기호를 정의해야합니다

set AppleScript's text item delimiters to {"»=", "¬ª="} 

이 (내 테스트 동안, 내가 찾은 당신의 "»="해야한다 "¬ª ="!로 설정 사실) 그리고

을 수행 할 수 있습니다

set AppleScript's text item delimiters to {"»=", "¬ª="} 
set myNotes to text items of myText 
set newText to "" 
repeat with I from 1 to (count of myNotes) --loop through each item 
    -- do what ever you need with 'item I of myNotes' 
    set Newtext to "this is my test" -- assign new text to be written 
end repeat 
당신은 루프에서 테스트를 조정해야합니다

: 텍스트가 시작하면 공백으로 예를 들어, 다음, 첫번째 반복 루프를 통해 각 텍스트 항목 (2 개 구분 기호 사이의 텍스트의 부분)에 액세스 항목은 예상되는 머리글이 아니라 공백입니다.

마지막 일 :

Set A to "This is my text sample" 
if A contains "is my" then 
    -- A contains 'is my' 
else 
    -- A do not contains 'is my' 
end if 

행운을 빕니다 : 텍스트 변수 뭔가 포함 된 경우 '포함'단어를 사용, 테스트하기!

관련 문제