0

我要做这样的事情

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

4

3 回答 3

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
于 2013-09-11T05:40:22.343 回答
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
于 2013-09-11T05:01:57.660 回答
0

你可以通过简单地写这个来做到这一点

"path of my file which name is = c:\" & txt1.Text & "." & txt2.Text
于 2013-09-11T05:17:53.760 回答