vb.net
2015-12-14 69 views 0 likes 
0

我把一個字符串替換掉了,但是我想用它作爲一個真正的vb.net函數,有這種可能嗎?例如:使用字符串作爲vb函數

dim str as string = "my task" 
dim func as string = "Replace(str, " ", "-")" 
dim result as string = 'here I must to use func string to have into result "my-task" 

幫我請

+0

爲什麼你需要'dim func as string =「Replace(str,」「,」 - 「)」'? 'Dim result As String = str.Replace(「」,「 - 」)'會給你結果 –

+0

只是看到這個 - http://hastebin.com/alubuxenak.vbs –

+0

我不僅需要使用這個函數,而且更多另一個函數left(),replace(),mid()但是我把這一切全部放到一個字符串中 –

回答

3

這是如何做到這一點:

Dim inputString As String = "my task" 
Dim methodName As String = "Replace" 
Dim arguments = New String() {" ", "-"} 

Dim result = CallByName(inputString, methodName, CallType.Method, arguments) 

這相當於:

Dim inputString As String = "my task" 
Dim result = inputString.Replace(" ", "-") 

雖然值得注意的是:它很可能有更好的方法來組織你的代碼。從字符串執行函數有多個缺點,您可能需要避免。

+0

非常感謝 –

相關問題