Dim suffix As String = "_version"
我有一个名为" Something_version1.jpg"
的文件我需要将其拆分,以便得到" Something_version"
以下内容让我" 1.jpg"
filename = filename.Split(New String() {suffix}, StringSplitOptions.None)(1)
以下内容让我和#34; Something"
filename = filename.Split(New String() {suffix}, StringSplitOptions.None)(0)
但我需要的是" Something_version"
后缀是动态的,可以改变。
希望这比我制作它更容易。
谢谢。
答案 0 :(得分:1)
如果你不关心" 1.jpg"部分,所有你想要的是后缀和后缀之前的部分,你可以做你上面的(第二个)获得前缀,并简单地连接前缀和后缀,以得到你的答案'正在寻找。
拆分电话可能有点过分,但它会完成这项工作。
答案 1 :(得分:0)
试试这个!
Option Strict On
Option Explicit On
Option Infer Off
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim suffix As String = "_version"
Dim searchThis As String = "something_version1.png"
MsgBox(GetPrefix(suffix, searchThis))
End Sub
Function GetPrefix(suffix As String, searchThis As String) As String
Dim suffixLocation As Integer = searchThis.IndexOf(suffix) + suffix.Count
Return searchThis.Substring(0, suffixLocation)
End Function
End Class