Extract a substring using PowerShell

前端 未结 8 977
灰色年华
灰色年华 2020-12-07 22:43

How can I extract a substring using PowerShell?

I have this string ...

\"-----start-------Hello World------end-------\"

I have to e

8条回答
  •  眼角桃花
    2020-12-07 23:04

    PS> $a = "-----start-------Hello World------end-------"
    PS> $a.substring(17, 11)
             or
    PS> $a.Substring($a.IndexOf('H'), 11)
    

    $a.Substring(argument1, argument2) --> Here argument1 = Starting position of the desired alphabet and argument2 = Length of the substring you want as output.

    Here 17 is the index of the alphabet 'H' and since we want to Print till Hello World, we provide 11 as the second argument

提交回复
热议问题