getEverythingBefore method
Returns the substring before the first occurrence of find.
Returns the original string if find is not found.
Implementation
String getEverythingBefore(String find) {
// Find the index of the target string.
final int atIndex = indexOf(find);
// Return the substring before the index, or the original string if not found.
return atIndex == -1 ? this : substring(0, atIndex);
}