2011-12-19 22 views
0

私は2つの文字列を比較し、重複した値と元の値の両方を取得する必要があります。
chkDuplicateValue関数を呼び出すと、戻り値に複製と元の両方を取得する必要がありますか? は、両方の文字列の区切り文字として機能します。文字列= "テスト、test53" 例アウトプットとして文字列は= "TEST1、TEST2、テスト" 薄暗いNewStrによってすでにとして 薄暗いoldStr:元の値:test1の、TEST2、テストは、値を複製test53:テスト機能の比較asp.net

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

「元の価値」は、ここでは誤称のようです。 – David

答えて

0
return oldStr.Split(',').Union(newStr.Spit(',')); 

、それはDistinctlistを返すために、重複して連合を返すように入会LINQの拡張メソッド

0

使用LINQの交差を使用して動作しない場合。 newStr ByRefを渡すと、重複しない文字列はnewStrに返されます。また、思い出してくれるあなたはLINQの経験を持っていますか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 
関連する問題