我需要比较两个字符串并获得重复和原始值 在调用chkDuplicateValue函数时,我需要在返回值中获取重复和原始值吗? ,充当字符串的分隔符。 Dim oldStr As String =“test1,test2,test” Dim newStr As String =“test,test53” 示例输出:原始值:test1,test2,test,test53 duplicate值:test
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim oldStr As String = "test1,test2,test"
Dim newStr As String = "test,test53"
Dim refinedString As String = chkDuplicateValue(newStr, oldStr)
'在调用此函数时,我需要在返回值中同时获取重复和原始文件吗?
Response.Write("Original Value" & refinedString(0))
Response.Write("duplicate Value" & refinedString(1))
'Example out put : Original Value :test1,test2,test,test53 duplicate Value : test
End Sub
Function chkDuplicateValue(ByVal newStr As String, ByVal oldStr As String) As String
Dim duplicate As String = ""
End Function
答案 0 :(得分:0)
return oldStr.Split(',').Union(newStr.Spit(','));
如果使用Join linq扩展方法
不起作用答案 1 :(得分:0)
使用Linq Intersect 返回重复项,使用 Union 返回Distinctlist。传递 newStr ByRef ,因此, newStr 将返回未重复的字符串。另外,请记住参考 System.Linq
Function chkDuplicateValue(ByRef newStr As String, ByVal oldStr As String) As String
Dim duplicate As String = ""
duplicate = String.Join(",",(newStr.Split(',').Intersect(oldStr.Split(','))).ToArray())
newStr = String.Join(",",(newStr.Split(',').Union(oldStr.Split(','))).ToArray())
return uplicate
End Function