Skip to main content
added 65 characters in body
Source Link
Marcodor
  • 5.9k
  • 1
  • 27
  • 26

Consider to pass the items as an array, like:

function Multipos(const A: array of string; const S: string): string; begin for var E in A do if Pos(E, S) > 0 then Exit(E); Result := ''; // Nothing found end; // sample callcalls Multipos(['word1', 'word2', 'word3'], 'this'sample istext awith sampleword2'); Multipos('word1#word2#word3'.Split(['#']), 'sample text with word2');`; 

To implement RequireAll functionality, stop on first failure. Just check what to return in that case.

Also, TStrings/TStringList could work for your needs. Check it's Delimiter and DelimitedText properties.

Consider to pass the items as an array, like:

function Multipos(A: array of string; const S: string): string; begin for var E in A do if Pos(E, S) > 0 then Exit(E); Result := ''; // Nothing found end; // sample call Multipos(['word1', 'word2', 'word3'], 'this is a sample text with word2');` 

To implement RequireAll functionality, stop on first failure. Just check what to return in that case.

Also, TStrings/TStringList could work for your needs. Check it's Delimiter and DelimitedText properties.

Consider to pass the items as an array, like:

function Multipos(const A: array of string; const S: string): string; begin for var E in A do if Pos(E, S) > 0 then Exit(E); Result := ''; // Nothing found end; // sample calls Multipos(['word1', 'word2', 'word3'], 'sample text with word2'); Multipos('word1#word2#word3'.Split(['#']), 'sample text with word2'); 

To implement RequireAll functionality, stop on first failure. Just check what to return in that case.

Also, TStrings/TStringList could work for your needs. Check it's Delimiter and DelimitedText properties.

Handle not found case
Source Link
Marcodor
  • 5.9k
  • 1
  • 27
  • 26

Consider to pass the items as an array, like:

function Multipos(A: array of string; const S: string): string; var E: string; begin for var E in A do if Pos(E, S) > 0 then Exit(E); Result := ''; // Nothing found end; // sample call Multipos(['word1', 'word2', 'word3'], 'this is a sample text with word2');` 

To implement RequireAll functionality, stop on first failure. Just check what to return in that case.

Also, TStrings/TStringList could work for your needs. Check it's Delimiter and DelimitedText properties.

Consider to pass the items as an array, like:

function Multipos(A: array of string; const S: string): string; var E: string; begin for E in A do if Pos(E, S) > 0 then Exit(E); end; // sample call Multipos(['word1', 'word2', 'word3'], 'this is a sample text with word2');` 

To implement RequireAll functionality, stop on first failure. Just check what to return in that case.

Also, TStrings/TStringList could work for your needs. Check it's Delimiter and DelimitedText properties.

Consider to pass the items as an array, like:

function Multipos(A: array of string; const S: string): string; begin for var E in A do if Pos(E, S) > 0 then Exit(E); Result := ''; // Nothing found end; // sample call Multipos(['word1', 'word2', 'word3'], 'this is a sample text with word2');` 

To implement RequireAll functionality, stop on first failure. Just check what to return in that case.

Also, TStrings/TStringList could work for your needs. Check it's Delimiter and DelimitedText properties.

Source Link
Marcodor
  • 5.9k
  • 1
  • 27
  • 26

Consider to pass the items as an array, like:

function Multipos(A: array of string; const S: string): string; var E: string; begin for E in A do if Pos(E, S) > 0 then Exit(E); end; // sample call Multipos(['word1', 'word2', 'word3'], 'this is a sample text with word2');` 

To implement RequireAll functionality, stop on first failure. Just check what to return in that case.

Also, TStrings/TStringList could work for your needs. Check it's Delimiter and DelimitedText properties.