如何在vb.net中声明文件路径?

时间:2013-09-11 04:55:11

标签: vb.net

我会做这样的事情,

If txt1.Text = "A" And txt2.Text = "B" Then
"path of my file which name is = c:/A.B"
End If

If txt1.Text = "C" And txt2.Text = "D" Then
"path of my file which name is = c:/C.D"
End If

我将如何做这样的事情?我正在使用vb.net

3 个答案:

答案 0 :(得分:2)

另一种方法是使用Path.Combine。

首先声明一个函数:

Private Function CreatePath(ByVal fileName As String,
                            ByVal extension As String) As String

    Return Path.Combine("C:\", fileName & "." & extension)

End Function

然后在需要的地方拨打电话。

Dim Path as string

If txt1.Text = "A" And txt2.Text = "B" Then
     "path of my file which name is = c:/A.B"
     Path = CreatePath("A", "B")
End If

If txt1.Text = "C" And txt2.Text = "D" Then
   "path of my file which name is = c:/C.D"
   Path = CreatePath("C", "D")
End If

答案 1 :(得分:0)

使用String.Format方法将它们连接在一起。

Dim path As String = String.Format("c:/{0}.{1}", txt1.Text, txt2.Text)

功能:

Private Function ConPath(a As String, b As String) As String
  Return String.Format("c:/{0}.{1}", a, b)
End Function

答案 2 :(得分:0)

你可以通过简单地写这个

来做到这一点
"path of my file which name is = c:\" & txt1.Text & "." & txt2.Text