![]() |
(SST) ShlWAPI.pas Version 1.08 |
---|---|
Developer Reference |
Performs a case-sensitive search for a (sub-)string in a string. |
Scope |
---|
Global (i.e. this function can be called/accessed from code in any unit that includes/uses (SST)ShlWAPI.pas). |
Parameters | |
---|---|
lpFirst [in] | Depending on which version of the function is called, a pointer to the null-terminated, ANSI or Unicode string, in which to search for the (sub-)string specified in parameter lpSrch. |
lpSrch [in] | Depending on which version of the function is called, a pointer to the null-terminated, ANSI or Unicode (sub-)string to search for. |
Return Values |
---|
If the string specified in lpFirst contains one or more exact copies of the string to search for (lpSrch), the function returns a pointer to the first occurrence of the sub-string within lpFirst. If an invalid parameter was specified (e.g. a NIL pointer or an empty string), or the function was unable to find the sub-string (lpSrch) in lpFirst, it returns NIL (= 0). |
Remarks |
---|
StrStr and StrStrI seem to have been introduced in the very first ShlWAPI.dll version (4.71) and continue to be supported under Windows 10. |
Example |
---|
PROCEDURE TForm4.TestShlWAPIStrStr(Sender : TObject); VAR strtosrchfor : STRING; VAR txttosearch : STRING; VAR apiretptr : POINTER; VAR newinfoline : STRING; BEGIN strtosrchfor := ''; txttosearch := ''; apiretptr := NIL; newinfoline := ''; strtosrchfor := 'fox'; txttosearch := 'The quick, brown fox jumped over the fence and hid in the fox burrow'; newinfoline := 'StrStr called with lpFirst (without the quotation marks) = "' + txttosearch + '" and lpSrch = ' + strtosrchfor; Memo1.Lines.Add(newinfoline); apiretptr := StrStr(PChar(txttosearch), PChar(strtosrchfor)); IF apiretptr <> NIL THEN newinfoline := 'StrStr returned a pointer to "' + PChar(apiretptr) + '"' ELSE newinfoline := 'StrStr returned NIL !'; Memo1.Lines.Add(newinfoline); strtosrchfor := 'FENCE'; //Note, that the word to search for is all in upper case txttosearch := 'The quick, brown fox jumped over the fence and hid in the fox burrow'; newinfoline := 'StrStr called with lpFirst (without the quotation marks) = "' + txttosearch + '" and lpSrch = ' + strtosrchfor; Memo1.Lines.Add(newinfoline); apiretptr := StrStr(PChar(txttosearch), PChar(strtosrchfor)); IF apiretptr <> NIL THEN newinfoline := 'StrStr returned a pointer to "' + PChar(apiretptr) + '"' ELSE newinfoline := 'StrStr returned NIL !'; Memo1.Lines.Add(newinfoline); strtosrchfor := ''; //Note, that the text to search for is an empty string txttosearch := 'The quick, brown fox jumped over the fence and hid in the fox burrow'; newinfoline := 'StrStr called with lpFirst (without the quotation marks) = "' + txttosearch + '" and lpSrch = ' + strtosrchfor; Memo1.Lines.Add(newinfoline); apiretptr := StrStr(PChar(txttosearch), PChar(strtosrchfor)); IF apiretptr <> NIL THEN newinfoline := 'StrStr returned a pointer to "' + PChar(apiretptr) + '"' ELSE newinfoline := 'StrStr returned NIL !'; Memo1.Lines.Add(newinfoline); txttosearch := 'The quick, brown fox jumped over the fence and hid in the fox burrow'; newinfoline := 'StrStr called with lpFirst (without the quotation marks) = "' + txttosearch + '" and lpSrch = NIL'; Memo1.Lines.Add(newinfoline); apiretptr := StrStr(PChar(txttosearch), NIL); //Note that we're passing a null pointer to the function IF apiretptr <> NIL THEN newinfoline := 'StrStr returned a pointer to "' + PChar(apiretptr) + '"' ELSE newinfoline := 'StrStr returned NIL !'; Memo1.Lines.Add(newinfoline); Memo1.Lines.Add(''); END; |
When run, the above code produces the following output: |
StrStr called with lpFirst (without the quotation marks) = "The quick, brown fox jumped over the fence and hid in the fox burrow" and lpSrch = fox StrStr returned a pointer to "fox jumped over the fence and hid in the fox burrow" StrStr called with lpFirst (without the quotation marks) = "The quick, brown fox jumped over the fence and hid in the fox burrow" and lpSrch = FENCE StrStr returned NIL ! StrStr called with lpFirst (without the quotation marks) = "The quick, brown fox jumped over the fence and hid in the fox burrow" and lpSrch = StrStr returned NIL ! StrStr called with lpFirst (without the quotation marks) = "The quick, brown fox jumped over the fence and hid in the fox burrow" and lpSrch = NIL StrStr returned NIL ! |
Requirements | |
---|---|
Unit: | Declared and imported in (SST)ShlWAPI.pas |
Library: | (SST)ShlWAPI.dcu/(SST)ShlWAPI.obj |
Unicode: | Implemented as ANSI (StrStr and StrStrA) and Unicode (StrStrW) functions. |
Min. ShlWAPI.dll version according to MS SDK doc.: | 4.71 |
Min. ShlWAPI.dll version based on SST research: | 4.71 |
Min. OS version(s) according to Microsoft SDK doc.: | Windows 2000, Windows NT 4.0 with Internet Explorer 4.0, Windows 98, Windows 95 with Internet Explorer 4.0 |
Min. OS version(s) according to SST research.: | Windows NT 4.0 with IE 4.0, Windows 95 with IE 4.0, Windows 98, Windows 2000 and later |
Document/Contents version 1.00 Page/URI last updated on 07.12.2023 |
Copyright © Stoelzel Software Technologie (SST) 2010 - 2015 |
Suggestions and comments mail to: webmaster@stoelzelsoftwaretech.com |