Lonewolf Online

The website of an amateur photographer, astronomer and petrolhead.

nPos Function

Return the nth position of search charactor within a string.

Return the nth position of search character within a string.

Usage:

pos := nPos(’/', ‘c:/mypath/to/somefile/’, 3);

pos = 13

function nPos(C: char; S: string; N: byte): byte;
var
  I, P, K: Integer;
begin
  Result := 0;
  K := 0;
  for I := 1 to N do
  begin
    P := Pos(C, S);
    Inc(K, P);
    if (I = N) and (P > 0) then
    begin
      Result := K;
      Exit;
    end;
    if P > 0 then
      Delete(S, 1, P)
    else
      Exit;
  end;
end;

 

Share/Save/Bookmark

 

Have Your Say

 

 

 

 

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment. The authors reserve the right not to publish any comments that they believe are hateful, racist, demeaning or otherwise inappropriate.

 

What Others Are Saying

There are no comments for this item yet. Click to Add Your Comments

 

  • Random Photographs
    • Macro Coin Experiment
    • Dragon Tree
    • Fireworks
    • Impreza Blows Up
    • Forest path
    • Small Toadstool
    • Black Cats Helicopter Attack Dive
    • Salt and Pepper
    • Poor Splatter
    • Aloe Aristata

  • Recent Additions
  • Search



  • Page copy protected against web site content infringement by Copyscape
This page was last updated on Monday, July 28th, 2008.
Unless otherwise stated, all photographs and content Copyright © 2000 - 2008 Tim Trott, All Rights Reserved. No graphics, photographs or content may be used without written permission.
Website Design and Graphics Copyright © 2005-2007 Tim Trott. home :: sitemap :: disclaimer:: contact