| PowerShell | Python |
|---|
| String | | |
| Multiline | | |
| Select Character | $str = 'Hello'
$str[0]
# H
| str = 'Hello'
str[0]
# 'H'
|
| Length | $str = 'Hello'
$str.Length
| |
| Remove whitespace at front and back | $str = ' Hello '
$str.Trim()
# Hello
| str = ' Hello '
str.strip()
# 'Hello'
|
| To Lowercase | $str = 'HELLO'
$str.ToLower()
# hello
| str = 'HELLO'
str.lower()
# 'hello'
|
| To Uppercase | $str = 'hello'
$str.ToUpper()
# HELLO
| str = 'hello'
str.upper()
# 'HELLO'
|
| Replace | $str = 'Hello'
$str.Replace('H', 'Y')
# Yello
| str = 'Hello'
str.replace('H', 'Y')
# 'Yello'
|
| Split | 'Hello, World' -split ','
# @('Hello', ' World')
| str = 'Hello, World'
str.split(',')
# ['Hello', ' World']
|
| Join | $array = @("Hello", "World")
$array -join ", "
[String]::Join(', ', $array)
| list = ["Hello", "World"]
", ".join(list)
|
| Formatting | $price = 49
$txt = "The price is {0} dollars"
$txt -f $price
| price = 49
txt = "The price is {} dollars"
print(txt.format(price))
|
| Formatting by Index | $price = 49
$txt = "The price is {0} dollars"
$txt -f $price
| price = 49
txt = "The price is {0} dollars"
print(txt.format(price))
|
| Formatting Strings | $price = 49
"The price is $price dollars"
| price = 49
f"The price is {price} dollars"
|