Ad

Getting A List Of Strings After A Start String

I'm building a Reddit bot that Replies with a link to the app that the redditor specified

What I want to achieve is that the user comments with this text

ilink: someapp, anotherapp

I have no problem getting the information and replying to the comment for a single argument

But not for multiple ones

Is it possible to get the line which contains the start string

ilink:

then split all arguments after that word which are separated by a comma , And put them into a result list

And thanks

Edit : Here is an example of multiple arguments with text that the bot should be able to find the arguments in

i like this games so much check em out \n ilink: awsomeGame, cuteGame

Ad

Answer

Assuming that the variable foo contains a string, then this should work:

if ("ilink:") in foo:
  arguments = foo[foo.find("ilink: ") + len("ilink: "):].split(",")

Hope that helps you with your bot!

Ad
source: stackoverflow.com
Ad