AI Zone Admin Forum Add your forum

NEWS: Chatbots.org survey on 3000 US and UK consumers shows it is time for chatbot integration in customer service!read more..

^nth() for nth word in a string?
 
 

Bear with me if this is another newbie question.

It looks like to be some typical requirement in processing a string of words. So I presume it must exist somewhere in CS. However I have read thru all the word manipulation functions but still not finding any clue.

I think I can write a macro for that but just do not want to reinvent the wheel.

The words in the string can be separated by underscore or space.

Many thanks.

 

 
  [ # 1 ]

technically, you use
@0 = ^burst(  $string)  to generate a set of words and then nth into that set. The omitted 2nd arg means accept both _ and space, as opposed to ^burst($string _) or ^burst($string ” “)

 

 
  [ # 2 ]

if you know the number of words will be “small” you can burst onto match variables and pick the right one if you know the index in advance.

 

 
  [ # 3 ]

Thank you for the guidance, Bruce. It really helps!

 

 
  login or register to react