You could also achieve this using the regexp package. But, in this case, it would probably be overkill.
On Tuesday, March 16, 2021 at 2:55:29 AM UTC-4 Sharan Guhan wrote: > Thanks for the tip! I just wanted to make sure, I am not missing some > basic API out there.. Will code this up :-) > > Sharan > > On Mon, Mar 15, 2021 at 11:18 PM Jan Mercl <0xj...@gmail.com> wrote: > >> On Tue, Mar 16, 2021 at 7:06 AM Sharan Guhan <shar...@gmail.com> wrote: >> >> > Seems a trivial problem, but unable to find the right imports to do >> this.. Want to search for a substring in a huge string ( output of a >> exec.command) and get the index for every occurrence of that substring. I >> used Index and LastIndex, both give first and last, but am looking for >> IndexNext kind of till the last occurrence.... >> > >> > For example : "Hello this is Golang program Golang has a variety of >> import utilities.I like to code in Golang" >> > >> > In the above example, I want an API which will return each occurrence >> of Golang >> >> The API is your keyboard ;-) Joking aside, it's easy to write a loop >> that uses Index to find out the first position, slice the string to >> remove the occurrence and find another until no more exists. >> > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/bed45b45-94e8-40f4-9049-22d919ff1803n%40googlegroups.com.