我有一个字符串替换,但我想用它作为一个真正的vb.net函数,有可能这样做吗?例如:
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 :(得分: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(" ", "-")
虽然值得注意:很可能有更好的方法来组织代码。从字符串执行函数有多个缺点,您可能希望避免这些。