Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: All-Topics
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
 
 
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 22-Dec-12 15:51pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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

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 Smile | :)
  Permalink  
v2
Comments
charuwaka at 23-Dec-12 0:40am
   
Please provide code in visual basic format
Sunnykumar08 at 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.
charuwaka at 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
Sunnykumar08 at 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.
charuwaka at 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!!!!!
Sunnykumar08 at 24-Dec-12 2:43am
   
Dear Charuwaka, I'm glad I could be of help. Please elaborate on the question above as I couldn't get the real picture what exactly what do you want to say. Also, Please accept my solution as answer (hover on the solution and it will display a button "Accept Answer"). It gives credit to the helper and you also will get some points. Thanks for the wishes... Merry Chrismas to you & Family !!
charuwaka at 24-Dec-12 2:50am
   
Thank You Very Much,
 
Merry Christmas To You And All Your Family Members!!!
 
Please try a code for me So My Project Completes or Leave It
 
If the obtained length of eliminated common characters is 6
My Default String Is Flames I will count from F Where The Position of 6 occurs i will cancel that character . and it goes on and i will second time from next of eliminated character Finally a letter remain that letter is displayed in 4th text box .Can u implement this logic
 
Please help me or just try i am beginner that's why i am asking this this new Logic. And I didn't find any reference for this in Google.
 
Thank you very for spending Your valuable time!!!!
Sunnykumar08 at 24-Dec-12 4:54am
   
Hi Charuwaka, still I'm not clear with the scenario. Do you want to skip every 6th matching character or you want to skip matching characters on every 6th position. Would be great if you could demonstrate this by a simple example.
charuwaka at 24-Dec-12 6:08am
   
Leave all Before What I said,
see i converted the Result of two strings to lenght and assigned value lenght to Rtn. according to that example :charu,swyrik two strings in two text boxes
after eliminating common terms :cshwayuik total =9 depending on this result i wrote below code But it always showing sister .please give me a code that displays according to lenght in third text box
 
Dim Rtn As String
Select Case Rtn
Case 1
Lnt = 1
TextBox3.Text = " Sister"
Case 2
Lnt = 2
TextBox3.Text = "Enemy"
Case 3
Lnt = 3
TextBox3.Text = "Enemy "
Case 4
Lnt = 4
TextBox3.Text = "Enemy"
Case 5

Lnt = 5
TextBox3.Text = "Friend"
Case 6
Lnt = 6
TextBox3.Text = "Marrage "
Case 7
Lnt = 7
TextBox3.Text = "Enemy"
Case 8
Lnt = 8
TextBox3.Text = "Affection"
Case 9
Lnt = 9
TextBox3.Text = "Enemy"
Case 10
Lnt = 10
TextBox3.Text = "Lover "
End Select
End Sub
End Class
 
There is no error while debugging always showing "sister" thats all event though lenght is 1,2,3,4,5,6,7,8,9,10;
 
please help me
Sunnykumar08 at 24-Dec-12 7:25am
   
What I can guess from the code above is, switch code block is all fine, check for the Rtn value before it's passing through the "switch case". Put a breakpoint on Rtn before it's passed inside switch statement to track whether it is changing or always "1". Hope you understand now. If still find trouble, share the code so that I can grab the point. Thanks.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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]
  Permalink  
v2
Comments
charuwaka at 23-Dec-12 3:29am
   
Dear Krunal,
 
please provide code for visual basic format not in C#
Krunal Rohit at 23-Dec-12 3:36am
   
use online converter..
ProgramFOX at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Hi,
 
Try this:
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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

* Hot categories
* Lounge
* Berita & Politik
* Computer
* Jokes
* Movies
* Supranatural
* Sports
* Games
* Otomotif
* Music
* Regional
  Permalink  

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

  Print Answers RSS
0 Kornfeld Eliyahu Peter 420
1 OriginalGriff 303
2 Yogesh Kumar Tyagi 230
3 Gihan Liyanage 99
4 sankarsan parida 90


Advertise | Privacy | Mobile
Web01 | 2.8.140827.1 | Last Updated 23 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100