Yanor.net/
Wiki
Blog
GitHub
Sandbox
開始行:
* 文字列操作 [#u5bf6d11]
** 結合 [#ta5f5000]
PS> "abc" + "def"
abcdef
** 置換 [#f72e3bbc]
*** -replace演算子 [#u8fab2d9]
PS> "abcdef" -replace "abc", "ABC"
ABCdef
*** Replaceメソッド [#q41288ce]
PS> "abcdef".Replace("abc", "ABC")
ABCdef
*** 正規表現 [#ic9c807d]
PS> "abc123" -replace "([a-z]+)\d{3}", '000$1'
000abc
- 上は量数指定{3}と前方参照$1の例
*** 1回だけ置換 [#n7ab885e]
PS> "123123123" -replace "1", "0"
023023023
PS> "123123123" -replace "1", "0$1"
023023023
*** Trim()で文字列前後のホワイトスペース除去 [#t8ed43a5]
PS brazil> " abc ".Trim()
abc
** 配列の中の文字列を結合(join) [#ica904bf]
PS> $strs = @("abc", "def")
PS> $strs -join ""
abcdef
** 文字列を分割して配列へ(split) [#jd06e998]
PS> $nums = "2016-04-01" -split "-"
PS> $nums[0], $nums[1], $nums[2]
2016
04
01
** ヒアストリング [#g5c6beed]
*** @" ... "@ - 変数展開する [#acb9e7ed]
PS> $val = "japan"
PS> $str = @"
>> hello,
>> $val
>> "@
PS> $str
hello,
japan
*** @' ... '@ - 変数展開しない [#y08dd5b7]
PS> $val = "japan"
PS> $str = @'
>> hello,
>> $val
>> '@
PS> $str
hello,
$val
終了行:
* 文字列操作 [#u5bf6d11]
** 結合 [#ta5f5000]
PS> "abc" + "def"
abcdef
** 置換 [#f72e3bbc]
*** -replace演算子 [#u8fab2d9]
PS> "abcdef" -replace "abc", "ABC"
ABCdef
*** Replaceメソッド [#q41288ce]
PS> "abcdef".Replace("abc", "ABC")
ABCdef
*** 正規表現 [#ic9c807d]
PS> "abc123" -replace "([a-z]+)\d{3}", '000$1'
000abc
- 上は量数指定{3}と前方参照$1の例
*** 1回だけ置換 [#n7ab885e]
PS> "123123123" -replace "1", "0"
023023023
PS> "123123123" -replace "1", "0$1"
023023023
*** Trim()で文字列前後のホワイトスペース除去 [#t8ed43a5]
PS brazil> " abc ".Trim()
abc
** 配列の中の文字列を結合(join) [#ica904bf]
PS> $strs = @("abc", "def")
PS> $strs -join ""
abcdef
** 文字列を分割して配列へ(split) [#jd06e998]
PS> $nums = "2016-04-01" -split "-"
PS> $nums[0], $nums[1], $nums[2]
2016
04
01
** ヒアストリング [#g5c6beed]
*** @" ... "@ - 変数展開する [#acb9e7ed]
PS> $val = "japan"
PS> $str = @"
>> hello,
>> $val
>> "@
PS> $str
hello,
japan
*** @' ... '@ - 変数展開しない [#y08dd5b7]
PS> $val = "japan"
PS> $str = @'
>> hello,
>> $val
>> '@
PS> $str
hello,
$val
ページ名: