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

{{percentage}} % positive

THANK YOU for your review!
<< PowerShell variables, data types and objects | PowerShell | PowerShell Syntax: compare and nest >>
Top articles in this section
PowerShell Log-Files: Logging into a textfile - write to file
Log files in PowerShell can be created via the Out-File command, via a custom function, or via PowerShell's built-in Transcript.
Log files in PowerShell can be created via the Out-File command, via a custom function, or via PowerShell's built-in Transcript.