[Python 3.1] stringBetween Function
def stringBetween(stringToSearch, startString, endString):
#stringBetween by Nat + Monarchy for Python 3.1
initPos = stringToSearch.find(startString)
if initPos == '-1':
return ''
else:
initPos = initPos + len(startString)
stringLength = stringToSearch.find(endString, initPos)
return stringToSearch[initPos:stringLength]
#Example usage
x = 'this is my [tag]dog[/tag]'
y = stringBetween(x, "[tag]", "[/tag]")
No idea if anyone will get anything out of this but enjoy.

Nice. What happens if you use -1 as the first part of stringToSearch[one:two]?
e.g. stringToSearch[-1:stringLength]
Error? Or does it start at 0 anyway?
What are you even saying? Could be that I'm tired as fuck but that made no sense to me...
An error probably. Why would you even do that that's in no way relevant?
If it defaulted -1 to 0, then the code could be shorted by quite a bit. Just brainstorming.
If a string is not found then the str.find fuction returns -1.
I know. Which is how it could be shortened.
Something along the lines of:
return x[x.find(start):x.find(end)]
And cut out the middle man that checks to see if it found the string, because if -1 defaults to 0 when taking substrings, then it would just return the entire string (or an empty string, like your program is doing now, if `end` isn't found, 'cause it would return x[-1:-1]).
No it wouldn't it would return the last character in the string...
Alright. That's what I was asking.
K thread over for you at least.