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.
#!/bin/sh
myFilename="$1"
# or
myFilename="/tmp/Test/myFile.txt"
# Get only the path
path_only=$(dirname "$myFilename")
# /tmp/Test
# if it is a local file in the path, then . will be prompted e.g. myFilename="myFile.txt"
# Filename only
filename_only=$(basename "$myFilename")
# myFile.txt
# get only filename without extention
filename_without_ext="${filename_only%.*}"
# myFile
# get only the extension
filename_extention_only="${myFilename##*.}"
# txt
# put them together again
myFilename_together="${path_only}/${filename_without_ext}.${filename_extention_only}"
# /tmp/Test/myFile.txt
266
MS Access VBA
Array
Dictionary Basics
' empty dict
Dim myDict As Dictionary
Set myDict = New Dictionary
' some static values
myDict.Add "key1", "value1"
myDict.Add "key2", "valueY"
myDict.Add "keyX", "value98"
' update a key programmatically
myDict.Remove "key1"
myDict.Add "key1", "new value"
' iterate
Dim strKey As Variant
Dim current_key As String
Dim strValue As String
For Each strKey In myDict.Keys()
current_key = strKey
strValue = myDict.Keys(strKey)
Next
' Exists
If myDict.Exists(strKey) Then
Debug.Print "yes"
End If
' get an specific item
Dim subdict As String
subdict = myDict.Keys("key2")
# valueY
267
PowerShell
Array
Dictionary Basics
# empty Hashtable
$myDict = @{}
# some static values
$myDict.Add("key1", "value1")
$myDict.Add("key2", "valueY")
$myDict.Add("keyX", "value98")
# update a key programmatically
$myDict.Remove("key1")
$myDict.Add("key1", "new value")
# iterate
Foreach ($key in $myDict.keys) {
$strKey = $key
$strValue = $Parameter[$key]
}
# Exists
If ($myDict.ContainsKey("key1") -eq $true) {
write-host "yes"
}
# get an specific item
$subdict = $myDict("key2")
# valueY
193
Python
Array
Dictionary Basics
# empty dict
myDict = {}
# some static values
myDict ={
"key1" : {"item1":"value1"},
"key2" : {"itemX":"valueY"},
"keyX" : {"item99":"value98"}
}
# update a key programmatically
myDict.update({"key1" = {"item2":"new value"}})
# iterate
for (key, subdict) in myDict.items():
current_key = key
current_subdict = subdict
# get an specific item
subdict = myDict.get("key2")
print subdict.get("itemX")
# valueY
191
Python
Encoding / Decoding
md5-Hash erzeugen
# https://docs.python.org/2/library/hashlib.html
import hashlib
a = "hello world"
b = 0.1
md5str = hashlib.md5(str(b) + a).hexdigest()
190
Python
Schleifen
While Schleife
i=10
while i<10:
i=i+1
print i
185
T-SQL
Strings
Prüfen ob eine Zahl in einem String enthalten ist
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
182
Batch
Variablen
Deklaration einer Variable
@echo off
SET myVariable=This is my content
SET myPathVariableWithBlanks="C:\Temp\Path With Blanks\File.txt"
echo %myVariable%
REM This is my content
echo %myPathVariableWithBlanks%
REM "C:\Temp\Path With Blanks\File.txt"
272
MS Access SQL
Datenbank
NULL Wert eines Feldes übersteuern
SELECT
FieldA
,Nz([FieldB,"This field is null") As FieldB_Nz
FROM TableA
180
T-SQL
Datenbank
NULL Wert eines Feldes übersteuern
SELECT ISNULL(MyColumn1, 1.0) AS MyColumnWithoutNULL;