Web Design that taps into the haromny and vision of your dreams.

nPos Function in Pascal

Find positions of string character inside another string

Written By on in Software Engineering

76 words, estimated reading time 1 minutes.

Return the nth position of string character 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;

Last updated on: Saturday 24th June 2017

 

Comments

There are no comments for this post. Be the first!

 

Leave a Reply

Your email address will not be published.





If you find something abusive or that does not comply with our terms or guidelines please flag it as inappropriate.

Copyright © 2001-2018 Tim Trott, all rights reserved. Web Design by Azulia Designs

This web page is licensed for your personal, private, non-commercial use only.

Disclaimer, Privacy & LegalSitemapContact Me