Click here to Skip to main content
15,884,836 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to compare two string values and remove common characters from both strings.

i tried this but got stuck how implement above mentioned logic

VB
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
 Dim fbn As String
 Dim Sbn As String
 fbn = TextBox1.Text.ToString
 Sbn = TextBox2.Text.ToString




Please help me i goggled but didn't find right answer

please give me that piece of code!!!!!!
Posted

Hi Charuwaka,

I think this is quite simple until you want to perform something specific. Below is an example:


VB
Dim str1, str2 As String
       str1 = "Sunny"
       str2 = "Manish"
       For Each c As Char In str1
           If (str2.IndexOf(c) > -1) Then
               str2 = str2.Remove(str2.IndexOf(c), 1)
               str1 = str1.Remove(str1.IndexOf(c), 1)
           End If
       Next

       Console.WriteLine("String 1: " + str1 + ", String 2:" + str2)
       Console.ReadLine()




Hope this helps.

Happy Coding :)
 
Share this answer
 
v2
Comments
[no name] 23-Dec-12 0:40am    
Please provide code in visual basic format
Sunny_Kumar_ 23-Dec-12 6:57am    
Hi Charuwaka, I've modified the answer for VB... please check and accept the answer if it works. It helps others finding the right answer in one go.
[no name] 23-Dec-12 21:26pm    
Dear Sunny,

Thank You Very Much i think your code worked, i tried this but i want to display my result in Third text box . How can i do that please tell me kindly

<pre lang="vb">Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim fbn As String
Dim Sbn As String

fbn = TextBox1.Text
Sbn = TextBox2.Text
For Each c As Char In fbn
If (Sbn.IndexOf(c) > -1) Then
Sbn = Sbn.Remove(Sbn.IndexOf(c), 1)
fbn = fbn.Remove(fbn.IndexOf(c), 1)
End If
Next

Console.WriteLine("String 1: " + fbn + ", String 2:" + Sbn)
Console.ReadLine()

End Sub
End Class</pre>

i have totaly three text boxes in third text box i want to display the result. after eliminating common terms in both strings the sum of characters in both strings = TextBox3.Text

Please
Sunny_Kumar_ 24-Dec-12 1:40am    
Hi Charuwaka, just append the code with like below:
"Textbox3.Text=Sbn+Fbn" that's all... this will show the output in third textbox. And please accept the solution as answer if it helped you for the reasons I mentioned above. Thanks.
[no name] 24-Dec-12 2:34am    
Dear SunnyKumar,

Your excellent Thanks for spending your valuable time>Merry Christmas To You & all Family!!!

is there any code to caluculate the below explained please try or leave it

this is the string FlAMES Think That Number Is 6 starting from i count FLAMES where it comes 6 i remove that character and i will count another letter where the character eliminated and finally in this process a character will be remained
i.e M for this i need code if completes my code will complete Please try if not just leave

Once Again thank You Very Much!!!!!
VB
Public Function stringLength(s1 As [String], s2 As [String]) As Integer
	For i As Integer = 0 To Math.min(s1.length(), s2.length()) - 1
		If s1.charAt(i) <> s2.charAt(i) Then
			Return s1.length() - i
		End If
	Next

	Return s1.length()
End Function
' from Stack Overflow

or else see here[^]....

[Edit]Code converted from C# to VB.NET[/Edit]
 
Share this answer
 
v2
Comments
[no name] 23-Dec-12 3:29am    
Dear Krunal,

please provide code for visual basic format not in C#
[no name] 23-Dec-12 3:36am    
use online converter..
Thomas Daniels 23-Dec-12 9:13am    
If the OP asks for VB.NET code, then you need to convert the C# code to VB.NET code.
Hi,

Try this:
VB
For i As Integer = 0 To Math.Min(fbn.Length, sbn.Length) - 1
	If fbn(i) = sbn(i) Then
		fbn.Remove(i, 1)
		sbn.Remove(i, 1)
	End If
Next

Hope this helps.
 
Share this answer
 
* Hot categories
* Lounge
* Berita & Politik
* Computer
* Jokes
* Movies
* Supranatural
* Sports
* Games
* Otomotif
* Music
* Regional
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900