From Clomosy Docs
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.
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.
Example
var
MainString, SubString: string;
Position: Integer;
{
MainString = 'Hello, you are learning Clomosy.';
SubString = 'Clomosy';
Position = Pos(SubString, MainString);
if (Position > 0)
ShowMessage('Substring found. Position: ' + IntToStr(Position));
else
ShowMessage('Substring not found.');
}
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 25 (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.
Output:
Substring found. Position: 25