如何删除两个字符串值中的常用字符(vb 2010) [英] How to remove common characters in two string values(vb 2010)
本文介绍了如何删除两个字符串值中的常用字符(vb 2010)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想比较两个字符串值并从两个字符串中删除常用字符。
i尝试了这个但是卡住了如何实现上面提到的逻辑
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!!!!!!
推荐答案
你好Charuwaka,
我认为这很简单,直到你想要执行特定的事情。下面是一个例子:
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 :)
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
或者参见 此处 [ ^ ] ....
代码从C#转换为VB.NET [ /编辑]
or else see here[^]....
Code converted from C# to VB.NET[/Edit]
您好,
试试这个:
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.
这篇关于如何删除两个字符串值中的常用字符(vb 2010)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文