0

We can check if a certain word/sentence is in a string by doing if "the example word" in string but I also want to find out the group of words that are after that word that we just found out, for example if

string = "The earth is shaped like Big Chungus"

Suppose I want to find out the series of words that are after "The", then how would I approach doing it?

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
  • 3
    Hi, welcome to StackOverflow! Please add tags to specify which language you're using – half of a glazier Apr 21 '21 at 10:13
  • Does this answer your question? [How to get a string after a specific substring?](https://stackoverflow.com/questions/12572362/how-to-get-a-string-after-a-specific-substring) – Tomerikoo Apr 23 '21 at 09:53

1 Answers1

0

Assuming you are doing this in python.

Say u have the string as follows:

string = "The earth is shaped like Big Chungus"

You can use the split method to cast the words in the list:

a=string.split()
print(a)

a will be as follows:

['The', 'earth', 'is', 'shaped', 'like', 'Big', 'Chungus']

Say you want to get all the words after a particular word you can use list slicing in combination with join keyword. In this case, you want to get all the words after The you can do as follows:

print(' '.join(a[1:]))

This will give output as follows:

earth is shaped like Big Chungus
Junaid
  • 159
  • 1
  • 15