Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
23
Task/Substring/PowerShell/substring.psh
Normal file
23
Task/Substring/PowerShell/substring.psh
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
# test string
|
||||
$s = "abcdefgh"
|
||||
# test parameters
|
||||
$n, $m, $c, $s2 = 2, 3, [char]'d', $s2 = 'cd'
|
||||
|
||||
# starting from n characters in and of m length
|
||||
# n = 2, m = 3
|
||||
$s.Substring($n-1, $m) # returns 'bcd'
|
||||
|
||||
# starting from n characters in, up to the end of the string
|
||||
# n = 2
|
||||
$s.Substring($n-1) # returns 'bcdefgh'
|
||||
|
||||
# whole string minus last character
|
||||
$s.Substring(0, $s.Length - 1) # returns 'abcdefg'
|
||||
|
||||
# starting from a known character within the string and of m length
|
||||
# c = 'd', m =3
|
||||
$s.Substring($s.IndexOf($c), $m) # returns 'def'
|
||||
|
||||
# starting from a known substring within the string and of m length
|
||||
# s2 = 'cd', m = 3
|
||||
$s.Substring($s.IndexOf($s2), $m) # returns 'cde'
|
||||
Loading…
Add table
Add a link
Reference in a new issue