0

ファイルパスの先頭から開始ディレクトリジョブ番号を取得したいファイルパスがあります。ファイルパス文字列から数値文字列を引き出す方法がわからないことを除いて。(つまり: filepath= Q:\2456_blah_blah\file.txt - または何か) '2456' を文字列として取得し、その数値文字列をフォームに作成した TextBox2 に入れたいと思います。私がこれまでに持っているコードは、必要な数値文字列の代わりに「0」を吐き出します。どんな助けでも大歓迎です。

  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Me.OpenFileDialog1.FileName = Nothing

    If Me.OpenFileDialog1.ShowDialog = System.Windows.Forms.DialogResult.OK Then
        Me.TextBox1.Text = Me.OpenFileDialog1.FileName

    End If

    If GetInfo() = True Then

        For Each Xitem In ExcelRowList

            Dim lvitem As ListViewItem
            lvitem = Me.ListView1.Items.Add(Xitem.C1)

        Next

    End If
'''Here is where I call the GetFilePathOnly function
    TextBox2.Text = GetFilePathOnly(TextBox1.Text)
End Sub

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

End Sub
'''Section below is what defines my number string, then I call it above for the Button1.Click operation(towards the end)
Private Function GetFilePathOnly(ByVal Fullpath As String) As String
    Dim File As String = Fullpath
    Dim number As Double = Val(File)
    Dim outcome As String = number.ToString 'File.Substring(0, File.LastIndexOf("\") + 1)
    Return outcome
End Function

ありがとう

4

2 に答える 2

0

怠惰な方法は、Splitを使用することです。

TextBox2.Text = path.Split("\")(1).Split("_")(0)
于 2012-10-19T16:17:48.923 に答える
0

正規表現も簡単に使用できます。

Dim numRegex As New Regex("\d+")
Dim number As String = numRegex.Match("Q:\2456_blah_blah\file.txt").Value
于 2012-10-19T17:29:28.173 に答える