Last active
August 29, 2015 14:16
-
-
Save G33kDude/d05d61ee2e0b4dcc546d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Macbeth := FileOpen("macbeth.txt", "r`r`n").Read() ; `r`n in the read options to normalize line endings to just "`n" | |
; Find which Act, scene, and dialog contains our phrase | |
; --- | |
; Replace multiple newlines with `r, which is not actually being used for anything. | |
; Makes it idea for a temporary separator. Then, split it based on `r (you can only | |
; split based on character, not based on string of characters) | |
Sections := StrSplit(RegExReplace(Macbeth, "\n{2,}", "`r"), "`r") | |
for each, Section in Sections | |
{ | |
if (InStr(Section, "ACT") == 1) ; match at start of string | |
Out_Act := StrSplit(Section, ".")[1] ; Only use what's before the first . | |
else if (InStr(Section, "Scene") == 1) | |
Out_Scene := StrSplit(Section, ".")[1] | |
else if (InStr(Section, "russian")) | |
{ | |
Out_Dialog := LTrim(Section) ; Remove the spaces before the character name | |
break | |
} | |
} | |
; Find character names in the scene | |
for each, Line in StrSplit(Macbeth, "`n") | |
{ | |
if (InStr(Line, "ACT") == 1) | |
Act := StrSplit(Line, ".")[1] | |
else if (InStr(Line, "Scene") == 1) | |
Scene := StrSplit(Line, ".")[1] | |
else if ((Line ~= "^ \S") && Act == Out_Act && Scene == Out_Scene) ; ~= is regex equals | |
Out_Characters .= ", " Trim(Line) | |
} | |
Sort, Out_Characters, U D`, ; Remove duplicates, Delimit with "," | |
Out_Characters := SubStr(Out_Characters, 3) ; Trim off the initial ", " | |
; Format the output | |
Out := Format("{}`n{}`nCharacters in scene: {}`nSpoken by {}", Out_Act, Out_Scene, Out_Characters, Out_Dialog) | |
MsgBox, % Out |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment