You may optionally enter a comparison operator (<, <=, >, >=, <> or =) at the beginning of each of your search values to specify how the comparison should be done.
String fullstring = new String("This is my string");
if (fullstring.contains("my"))
{
// I found it!!
}
116
Delphi
Strings
String nach einem Teilstring durchsuchen
searchFor:='this';
text:='this is a simple text';
if pos(searchFor,text)>0 then
begin
ShowMessage('found');
end;
133
VB.NET
Strings
String nach einem Teilstring durchsuchen
Dim longStr = "This is a long string"
Dim searchFor = "long"
position = InStr( longStr, searchFor )
138
T-SQL
Datenbank
String nach einem Teilstring durchsuchen
-- Find characters which are also special characters for search terms, e.g. % or _
-- see also: http://msdn.microsoft.com/en-us/library/ms179859%28v=sql.105%29.aspx
SELECT * FROM table_1 WHERE column_1 LIKE '%!_%' ESCAPE '!'
-- Find results which includes the character "_". The escape character is defined as "!"
161
Python
Strings
String nach einem Teilstring durchsuchen
# http://www.tutorialspoint.com/python/string_find.htm
# this function is case sensitive
fullstring = "This is my string"
searchFor = "my"
startPosition = fullstring.find(searchFor, 0, len(fullstring))
# startPosition will have 8
if startPosition>=0:
print "I found it!"
startPosition = fullstring.upper().find(searchFor.upper()) # case insensitive
229
PowerShell
Strings
String nach einem Teilstring durchsuchen
# See also a good hint with explanation between like and contains:
# http://windowsitpro.com/blog/powershell-contains
$fullstring = "This is my string";
if ($fullstring -like "*my*")
{
Write-Host "found" -ForegroundColor Green;
}
else
{
Write-Host "nope" -ForegroundColor Red;
}
237
MySQL
Strings
String nach einem Teilstring durchsuchen
SELECT
myString
,locate('#',myString,5) AS findPosition -- Result is: 8
,left(myString,locate('#',myString,2)-1) AS ExtractedString -- Result is: abc
,left(myString,locate('#',myString,5)) AS ExtractedString -- Result is: abc#def#
FROM
(
SELECT
'abc#def#ghj' AS myString
) dummyString
42
PHP
HTTP Form Submit
POST Werte abfragen
if ($_POST["submitName"]=="submitValue")
{
echo "Button submitValue gedrückt";
}
43
Bash Script
Sonstiges
Kopfzeile sh-Datei
#!/bin/sh
# Einfaches Beispiel ...
44
Delphi
Filehandling
Datei auf dem Betriebssystem ausführen
procedure TForm1.MenuDummy1Click(Sender: TObject);
var
ExeName : array[0..255] of char;
myFile : String;
begin
myFile:='winword.exe';
Showmessage('Starte: ' + myFile);
StrPCopy(ExeName, myFile);
ShellExecute(MainForm.Handle, 'open', ExeName, nil, nil, SW_SHOWNORMAL);
// Drucken geht dann so (siehe auch Dateitypen im Windows Explorer):
ShellExecute(MainForm.Handle, 'print', ExeName, nil, nil, SW_SHOWNORMAL);
end;