CodeCogs - A iteractive open source Numerical library in C/C++, with wrappers for .NET and Excel Welcome... Login
Site Map
shopping cart
OSX compatibleWindows compatibleLinux compatible
Search CodeCogs
Numerical Components
Worked Examples

Valid RSS

strings

nth word

Available under GPL (Free) and Commercial licence
get a GPL licence
COST (GBP)
this unit 2.32
sub units 0.00
add a commercial licence to your cart
0
viewed 1370 times and licensed 12 times

Returns the location to the nth word in str.

Controller: CodeCogs    Contact Controller

+View other versions (2)
Contents hide toc

Interface

#include <codecogs/strings/nth_word.h>

using namespace Strings;

int nth_word (const char *str, int n, int offset=-1)
Returns the location to the nth word in str.
ExcelInteger cc_stringsNth_word (String str, Integer n, Integer offset)
This function is available as a Microsoft Excel add-in.

Function Documentation

Nth Word Calculator
  
Add calculator to website or email
 
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:
#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. [const]
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:

You do not own any licences for this module.
To view or download source code you must get a GPL licence or buy a commercial licence.

buy now     get GPL     add to cart

For advanced download and development options Register with CodeCogs. Already a Member, then Login.


Page Comments

Format Excel Equations

  You must login to leave a messge


Last Modified: 18 Oct 07 @ 17:07     Page Rendered: 2008-11-21 00:02:23

Valid CSS!   Valid XHTML 1.0 Transitional