ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Check all string in comma separated string exist in other using C# and VB.Net in ASP.Net<p>Hi <a class="username" rel="manvendra45">manvendra45</a>,</p> <p>Refer below sample code.</p> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { &nbsp;&nbsp;&nbsp; if (!this.IsPostBack) &nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string parentString = &#34;AAA,BBB,CCC&#34;; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string[] parentarray = parentString.Split(&#39;,&#39;); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string childstring = &#34;AAA,AA,CCC&#34;; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string[] childarray = childstring.Split(&#39;,&#39;); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string notmatchvalue = &#34;&#34;; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach (var child in childarray) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Boolean checkExists = Array.Exists(parentarray, x =&gt; x == child); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (checkExists == false) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; notmatchvalue = child; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp; } }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load &nbsp;&nbsp;&nbsp; If Not Me.IsPostBack Then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim parentString As String = "AAA,BBB,CCC" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim parentarray As String() = parentString.Split(","c) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim childstring As String = "AAA,AA,CCC" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim childarray As String() = childstring.Split(","c) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim notmatchvalue As String = "" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For Each child In childarray &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim checkExists As Boolean = Array.Exists(parentarray, Function(x) x = child) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If checkExists = False Then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; notmatchvalue = child &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit For &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next &nbsp;&nbsp;&nbsp; End If End Sub</pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/146960/Check-all-string-in-comma-separated-string-exist-in-other-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/146960/Check-all-string-in-comma-separated-string-exist-in-other-using-C-and-VBNet-in-ASPNet/Wed, 11 Sep 2019 04:24:13 GMTCheck all string in comma separated string exist in other using C# and VB.Net in ASP.Net<p>Here is anwser using Array&nbsp;</p> <pre class="brush: csharp">string parentString = &#34;AAA,BBB,CCC&#34;; String[] parentarray=parentString.Split(&#39;,&#39;) ;//fill string as element in Array string childstring = &#34;AAA,AA,CCC&#34;; childstring =childstring.split(&#39;,&#39;); string notmatchvalue=&#34;&#34;; foreach (var child in childstring ) { Boolean checkExists = Array.Exists(parentarray, x =&gt; x ==child ); if(checkExists ==false) { notmatchvalue=child // do whatever want break ;// it will break the foreach loop once get false and it will show this value is not matched with parentarray element } } </pre> <p>in this case "AA" will retrun false becuase it will not match to any array element.</p>https://www.aspforums.net:443/Threads/146960/Check-all-string-in-comma-separated-string-exist-in-other-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/146960/Check-all-string-in-comma-separated-string-exist-in-other-using-C-and-VBNet-in-ASPNet/Wed, 11 Sep 2019 11:50:05 GMT