Skip to content

Instantly share code, notes, and snippets.

@freakinbook
Created September 28, 2021 11:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save freakinbook/2bb3d513a248d4af5c68900c8996f6ad to your computer and use it in GitHub Desktop.
Save freakinbook/2bb3d513a248d4af5c68900c8996f6ad to your computer and use it in GitHub Desktop.
private String printTextPerRole(String[] roles, String[] textLines) {
StringBuilder sb = new StringBuilder();
for (String role : roles){
sb.append(role + ":\n");
for (int line = 0; line < textLines.length; line++){
int indexOfColon = textLines[line].indexOf(":");
String roleInLine = textLines[line].substring(0,indexOfColon);
if (role.equalsIgnoreCase(roleInLine)){
int lineNumInScript = line + 1;
int indexOfSpeech = indexOfColon+1;
String speech = textLines[line].substring(indexOfSpeech);
sb.append(lineNumInScript + ")" + speech +"\n");
}
}
sb.append("\n");
}
return sb.toString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment