Find character position and update file name

前端 未结 5 1298
离开以前
离开以前 2021-01-07 22:01

What function might I use to find a character position in a string using PowerShell 2.0.

i.e I would use CHARINDEX or PATINDEX if using SQL Server.

I looke

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-07 22:43

    If you use Excel, then the command would be Find and MID. Here is what it would look like in Powershell.

     $text = "asdfNAME=PC123456<>Diweursejsfdjiwr"
    

    asdfNAME=PC123456<>Diweursejsfdjiwr - Randon line of text, we want PC123456

     $text.IndexOf("E=")
    

    7 - this is the "FIND" command for Powershell

     $text.substring(10,5)
    

    C1234 - this is the "MID" command for Powershell

     $text.substring($text.IndexOf("E=")+2,8)
    

    PC123456 - tada it has found and cut our text

    -RavonTUS

提交回复
热议问题