字符串 = 24-06-1966 显示重复编号 6, 6, 6 显示不重复的编号 2, 4, 1, 9
你好
如果有人可以帮助我从数字字符串中获取或显示重复数字
TxtBxString.Text ="24-06-1966"
TxtBxRepetitive.Text ="6, 6, 6"
Textbox1.Text = "2, 4, 1, 9"
您的帮助将不胜感激
谢谢 固态硬盘
2. 奥利弗我不明白你的说法
首先我认为我应该替换“-”,“”
因此我使用了以下
Dim replacedStr As String = TxtBxString.Text.Replace("-", "")
然后用从该论坛线程38690124采用的以下编码来拆分上面的replacedStr,但作为VBA excel的编码对我来说没有用 而不是 VB.NET
以 Redim 数字开头的行也给了我错误 “ReDim”语句不能再用于声明数组变量 因此,要检查 Textbox1.Text 或 Msgbox 无法获得拆分字符串的结果。那么我如何正确地得出这个?
Sub SplitLong()
Dim digits() As Long
Dim intValue As Long
Dim i As Long
Dim strValue As String
'intValue = 123456789
'strValue = intValue
strvalue = TxtBxString.Text
ReDim digits(Len(strValue) - 1) As Long
For i = 1 To Len(strValue)
digits(i - 1) = Mid$(strValue, i, 1)
Next
End Sub
希望这是正确的逻辑?如果没有,我们将不胜感激您的帮助
谢谢 固态硬盘
这是我的尝试(我用字符串替换了文本框进行测试,但它是相同的):
Dim TxtBxString_Text As String = "24-06-1966"
Dim TxtBxRepetitive_Text, Textbox1_Text As String
Dim count As Integer
For i As Integer = 0 To 9 'Check every possible digit. I u don't want the zero, set "i as integer = 1 to 9"
If TxtBxString_Text.Contains(i.ToString) Then 'Check if the digit is in the original string
count = TxtBxString_Text.Count(Function(c) c = i.ToString) 'how many times "i" is written?
If count > 1 Then 'It's a repetitive char
For j As Integer = 0 To count - 1
TxtBxRepetitive_Text += i.ToString + ", "
Next
Else 'It's a single char
Textbox1_Text += i.ToString + ", "
End If
End If
Next
MessageBox.Show("TxtBxRepetitive.Text= " + TxtBxRepetitive_Text + Environment.NewLine +
"Textbox1.Text= " + Textbox1_Text)
结果将是: