I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com

Valid RSS

get GPL
COST (GBP)
this unit 3.61
sub units 0.00
+
0
Strings

nth word

Returns the location to the nth word in str.
Controller: CodeCogs

get GPL add to cart

Interface

C++
Excel
HTML

Nth Word

 
intnth_wordconst char*str
intn
intoffset = -1 )
Returns the location of start to the (n+1)th word within a string. A word is defined by a continuous sequence of characters consisting of a-z and A-Z

Example 1

#include <codecogs/strings/nth_word.h>
int main()
{
  const char str[] = "The quick brown fox jumps over the lazy dog";
  printf("\nThe start of the 5th word is at location: %d", Strings::nth_word(str, 4));
  printf("\nThe 2nd last word is at location: %d", Strings::nth_word(str,-2));
  printf("\nThe location of next word after the 12th letter is: %d", Strings::nth_word(str, 1, 12)); 
  return 0;
}
Output:
The 4th word is at location: 20
The 2nd last word is at location: 35
The location of next word after the 12th letter is: 16

Parameters

strthe character string containing a collection of words.
nthe word number you wish to find. The current word (or location) is n=0, so to find the start of the next word use n=1, etc. A negative value of n will word backwards to find previous words relative to offset. If offset is undefined, then a negative value of n will start from the end of the string.
offsetthe location within the string to start from. By default this is the first character within the string when n>0 and the last character within the string when n<0.
Source Code

Source code is available when you agree to a GP Licence or buy a Commercial Licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.