PowerShell convert string / manipulation: substring etc.
In this article I show a few examples for manipulating strings (character strings)
.ToUpper()
Converts a string to uppercase letters
PS C:\> $("test").ToUpper()
Result:
TEST
.ToLower()
Converts a string into lowercase letters
PS C:\> $("TEST").ToLower()
Result:
test
.Contains()
Tests a string whether a certain string is present
PS C:\> $("TEST").Contains("ES")
Result:
True
.StartsWith()
Tests a string to see if it starts with a certain string.
PS C:\> $("TEST").StartsWith("TE")
Result:
True
.EndsWith()
Tests a string to see if it ends with a specific string.
PS C:\> $("TEST").EndsWith("ST")
Result:
True
.Replace()
Replaces a specified string within a string
PS C:\> $("TEST").Replace("TE","ersetzt")
Result:
ersetztST
.Substring()
Replaces parts of a string based on their position
PS C:\> $("TEST").Substring("1")
Result:
EST
here is another example: start and end position:
PS C:\> $("TEST").Substring("1","2")
Result:
ES
- 1 ... after the first character
- 2 ... up to the 2nd character
If only the end position should be used, it looks like this:
PS C:\> $("TEST").Substring("","3")
Result:
TES
.TrimStart()
Removes certain characters at the beginning of the string:
PS C:\> $("TEST").TrimStart("TE")
Result:
ST
({{pro_count}})
Rate Post:{{percentage}} % positive
({{con_count}})