View PlGroup Strings
ID | 17 |
Text | Strings |
Title | Not set |
PlItems
- $myString = "A;B;C;D;E";
$myPieces = explode(";",$myString); // erzeigt ein Array mit den einzelnen Zeichen
echo $myPieces[2]; // gibt C aus
- String myString = new String;
String[] myPieces = new String;
myString = "A;B;C;D;E";
myPieces = myString.split(";"); // erzeugt ein Arrey mit den einzelnen Zeichen
System.out.println(myPieces[2]); // gibt C aus
- myString="A;B;C;D;E"
Write !,$Piece(myString,";",3) // gibt C aus
- // is case sensitiv
// use stristr for case insensitive
$email = 'name@example.com';
$domain = strstr($email, '@');
echo $domain; // Ausgabe: @example.com
$user = strstr($email, '@', true); // Ab PHP 5.3.0
echo $user; // Ausgabe: name
- Set fullstring="This is my string"
Set searchfor="my"
If $Find(fullstring, searchfor) Do
. Write !,"I found it!!"
. Quit
- String fullstring = new String("This is my string");
if (fullstring.contains("my"))
{
// I found it!!
}
- procedure foo()
var
str1: String;
begin
str1:=StringReplace('Hello World...','...',[rfReplaceAll, rfIgnoreCase]);
// Output of str1 => "Hello World"
end
- string myString = " test ";
Console.WriteLine(myString.Trim());
//Gibt: "test" aus.
- string myString = "Benzinverbrauch";
Console.WriteLine(myString.Substring(2, 8));
//Ausgabe: "nzinverb"
- private bool IsInteger(string inputString)
{
int i;
return int.TryParse(inputString, out i);
}
- string CreateStringLength(int length)
{
try
{
string tempString = Guid.NewGuid().ToString().ToLower();
tempString = tempString.Replace("-", string.Empty);
while (tempString.Length < length)
{
tempString += tempString;
}
tempString = tempString.Substring(0, length);
return tempString;
}
catch
{
MessageBox.Show("Zu wenig Zwichenspeicher verfügbar!");
return string.Empty;
}
}
- string myString = "!";
String.Concat("Hallo ", "Welt ", myString);
- searchFor:='this';
text:='this is a simple text';
if pos(searchFor,text)>0 then
begin
ShowMessage('found');
end;
- DECLARE @TestString VarChar(max) = 'abcdeeeff'
DECLARE @SearchFor VarChar(1) = 'e'
SELECT Len(@TestString)-Len(replace(@TestString,@SearchFor,'')) As Count
- -- Da im Deutschen das Trennzeichen für eine
-- Dezimalstelle ein Komma ist, muss dieses erst
-- gegen einen Punkt ersetzt werden
select cast(replace(cast('12.12' as varchar(10)),',','.') as numeric(12,2))
- SELECT split_part('A;B;C;D;E',';',2)
-- Result: B
- Dim longStr = "This is a long string"
Dim searchFor = "long"
position = InStr( longStr, searchFor )
- myTestString = "abc;def;ghj/1";
splittedString = myTestString.split(";");
elementTwo = splittedString[1];
// => def
- myString = "This is a string, containing some words. Try it, if you don't believe ;-)";
// Get the count of commas in the string:
cntCommas = myString.split(",").length-1;
// => 2
- -- Bei PL/pgSQL sollte man die Funktion concat verwenden.
-- Felder verbinden mit || kann zu NULL im Ergebnisfeld führen
SELECT
field_a
,field_b
,NULL as field_c
,concat(field_a, field_b, field_c) as together
FROM
table_1
- # 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
- myString = "Benzinverbrauch"
print myString[2:10]
# Ausgabe: "nzinverb"
- # http://wiki.ubuntuusers.de/Shell/Bash-Skripting-Guide_f%C3%BCr_Anf%C3%A4nger#Variablen-abgrenzen
#!/bin/bash
subString1="Hello"
subString2='World!'
echo "${subString1} ${subString2}"
Hello World!
echo "${subString1} ${subString2}. I'm in here ;-)"
# Hello World!. I'm in here ;-)
- SELECT
value
,CASE
WHEN PATINDEX('%[0-9]%',value) > 0 THEN 1
ELSE 0
END AS CheckIfStringContainsANumber
FROM
(
SELECT 'String w/o a number' AS value
UNION ALL
SELECT 'This string contains 1 as a number' AS value
) subQuery1
-- value | CheckIfStringContainsANumber
-- ------------------------------------------------------------------
-- String w/o a number | 0
-- This string contains 1 as a number | 1
- myString = "A;B;C;D;E"
myPieces = myString.split(";") # erzeugt ein Arrey mit den einzelnen Zeichen
print myPieces[2] # gibt C aus
- myString = "abc";
mySubString = myString.substring(0,2);
// ab
- /*
Cell A1 contains text "abc#def"
*/
=SUBSTITUTE(A1;"*";"/")
/*
Result will be: "abc/def"
*/
- # http://www.tutorialspoint.com/python/string_replace.htm
str1 = "abc#def"
str1 = str1.replace("#",';")
print str1
# Output: abc;def
- DECLARE @searchFor_Charindex Varchar(10)
DECLARE @searchFor_Patindex Varchar(10)
DECLARE @text Varchar(100)
SET @searchFor_Charindex = 'simple'
SET @searchFor_Patindex = '%simple%' -- Remember the %. Patindex can also be used for RegEx!
SET @text = 'this is a simple text'
SELECT CHARINDEX(@searchFor_Charindex, @text) AS Position_Charindex
SELECT PATINDEX(@searchFor_Patindex, @text) AS Position_Patindex
-- 11
- searchFor:='simple';
text:='this is a simple text';
ShowMessage(IntToStr(pos(searchFor,text)));
// 11
- SELECT
field_a
,field_b
,field_a || field_b as together
FROM
table_1
- // http://php.net/manual/de/function.str-replace.php
$str1 = "abc#def";
$str1 = str_replace("#",";",$str1);
echo $str1;
# Output: abc;def
- $str1 = "abc#def";
$str1 = $str1.Replace("#",";");
write-host $str1;
# Output: abc;def
- # 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;
}
- -- Not a real solution, but a workaround if you have rights to create a function
-- see: http://blog.fedecarg.com/2009/02/22/mysql-split-string-function/
-- same problem with MSSQL.
CREATE FUNCTION SPLIT_STR(
StringToBeSplitted VARCHAR(255),
delimiter VARCHAR(12),
position INT
)
RETURNS VARCHAR(255)
RETURN REPLACE(SUBSTRING(SUBSTRING_INDEX(StringToBeSplitted, delimiter, position),
LENGTH(SUBSTRING_INDEX(StringToBeSplitted, delimiter, position -1)) + 1),
delimiter, '');
SELECT SPLIT_STR(string, delimiter, position);
- 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
- // http://php.net/manual/de/function.substr.php
$myString = "Benzinverbrauch";
echo substr($myString,2,8);
//Ausgabe: "nzinverb"
- //http://us2.php.net/manual/de/function.strtoupper.php
$myString = "my lovely Mr Singing Club";
echo strtoupper($myString);
// MY LOVELY MR SINGING CLUB
//http://php.net/manual/de/function.strtolower.php
echo strtolower($myString);
- myString = "my lovely Mr Singing Club"
print myString.upper()
// MY LOVELY MR SINGING CLUB
print myString.lower()
- SELECT
'my lovely Mr Singing Club' AS myString
,UPPER('my lovely Mr Singing Club') AS myStringUpper
,LOWER('my lovely Mr Singing Club') AS myStringLower
-- myString: my lovely Mr Singing Club
-- myStringUpper: MY LOVELY MR SINGING CLUB
-- myStringLower: my lovely mr singing club
- $myString = "nothingspecial";
$uc = ucwords($myString);
echo $uc;
// Nothingspecial
- # Siehe auch: http://www.php2python.com/wiki/function.ucwords/
myString = "nothingspecial"
import string
uc = string.capwords(myString)
print(uc)
# Nothingspecial
- # In PowerShell such variables are called: Here-Strings
$mySQLString = @"
SELECT 1
FROM dbo.TestTable
WHERE 1=1
"@
- SELECT LTRIM(RTRIM(' x text x '))
- myText = " x text x \r\n"
print myText.strip()
- -- Gets only result with 4 "/" in the the field relativePath
SELECT
id
,albumRoot
,relativePath
,date
,caption
,collection
,icon
,LENGTH(relativePath) - LENGTH(REPLACE(relativePath,'/','')) AS `occurrences`
FROM Albums
WHERE LENGTH(relativePath) - LENGTH(REPLACE(relativePath,'/',''))=4
;
- WITH cte_example AS
(
SELECT 5 AS int_example UNION ALL
SELECT 10 AS int_example UNION ALL
SELECT 50 AS int_example
)
SELECT
int_example,
RPAD(int_example::text, 3, '0'),
LPAD(int_example::text, 3, '0')
FROM cte_example
- WITH cte_example AS
(
SELECT 5 AS int_example UNION ALL
SELECT 10 AS int_example UNION ALL
SELECT 50 AS int_example
)
SELECT
int_example,
substr('0000000'||ROW_NUMBER() OVER(ORDER BY int_example)||'00', -8, 8) AS example_result
FROM cte_example
;