Find character position and update file name

前端 未结 5 1286
离开以前
离开以前 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:36

    I know this thread is a bit old but, I was looking for something similar and could not find it. Here's what I came up with. I create a string object using the .Net String class to expose all the methods normally found if using C#

    [System.String]$myString
     $myString = "237801_201011221155.xml"
     $startPos = $myString.LastIndexOf("_") + 1 # Do not include the "_" character
     $subString = $myString.Substring($startPos,$myString.Length - $startPos)
    

    Result: 201011221155.xml

提交回复
热议问题