From Clomosy Docs

Revision as of 11:31, 14 August 2023 by ClomosyManager (talk | contribs) (Created page with "In the Clomosy programming language, the Pos function allows you to find the position of a specific substring within another string. This function searches for a given substring within a target string and returns its position. The usage of the Pos function is as follows: function Pos(const SubStr: string; const Str: string): Integer; Here: SubStr: The substring to be searched for. Str: The main string in which the search will be performed. Function result: Returns th...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

In the Clomosy programming language, the Pos function allows you to find the position of a specific substring within another string. This function searches for a given substring within a target string and returns its position. The usage of the Pos function is as follows:

function Pos(const SubStr: string; const Str: string): Integer;

Here:

SubStr: The substring to be searched for. Str: The main string in which the search will be performed. Function result: Returns the position of the substring found (starting from 1). If the substring is not found, it returns a value of 0.

Example:

var
  MainString, SubString: string;
  Position: Integer;
begin
  MainString := 'Hello, you are learning Clomosy.';
  SubString := 'Clomosy';

  Position := Pos(SubString, MainString);

  if Position > 0 then
    ShowMessage('Substring found. Position: ' + 
IntToStr(Position))
  else
    ShowMessage('Substring not found.');
end;


In this example, the substring "Clomosy," which is SubString, is found within the string "Hello, you are learning Clomosy," which is MainString. As a result, it will return 10 (the starting position).


The Pos function returns only the position of the first occurrence of the substring. If you want to find the substring multiple times, you may need to use loops or different approaches.