VB统计字符串中某字符的个数
text1.text中内容为:我,是,谁,我,就,是,不,告,诉,你,我,是,谁,我想在text2.text中输出他0个你1个我3个代码如何写?在text2.text中输...
text1.text中 内容为:我,是,谁,我,就,是,不,告,诉,你,我,是,谁,
我想在text2.text中输出
他0个
你1个
我3个
代码如何写?
在text2.text中输出
他0个
你,不1个
我3个
代码又应该如何写? 展开
我想在text2.text中输出
他0个
你1个
我3个
代码如何写?
在text2.text中输出
他0个
你,不1个
我3个
代码又应该如何写? 展开
3个回答
展开全部
Private Sub Command1_Click()
Dim w As Integer, n As Integer, t As Integer '我你他的个数
For i = 1 To Len(Text1)
Select Case Mid(Text1, i, 1)
Case "我"
w = w + 1
Case "你"
n = n + 1
Case "他"
t = t + 1
End Select
Next
Text2 = "我" & w & "个,你" & n & "个,他" & t & "个"
End Sub
Dim w As Integer, n As Integer, t As Integer '我你他的个数
For i = 1 To Len(Text1)
Select Case Mid(Text1, i, 1)
Case "我"
w = w + 1
Case "你"
n = n + 1
Case "他"
t = t + 1
End Select
Next
Text2 = "我" & w & "个,你" & n & "个,他" & t & "个"
End Sub
展开全部
'先设置Text2的MultiLine为 True
Private Sub Form_Load()
Dim HeN As Integer, YouN As Integer, MeN As Integer, A() As String
HeN = 0
YouN = 0
MeN = 0
A = Split(Trim(Text1.Text), ",")
For i = 0 To UBound(A)
If A(i) = "他" Then
HeN = HeN + 1
ElseIf A(i) = "你" Then
YouN = YouN + 1
ElseIf A(i) = "我" Then
MeN = MeN + 1
End If
Next
Text2.Text = ""
Text2.Text = "他" & HeN & "个" & vbCrLf & "你" & YouN & "个" & vbCrLf & "我" & MeN & "个"
End Sub
一般情况下“你,不1个”这种是不能设置的,除非你事先知道“你”和“不”的字数是一样的才可以这样显示。
Private Sub Form_Load()
Dim HeN As Integer, YouN As Integer, MeN As Integer, A() As String
HeN = 0
YouN = 0
MeN = 0
A = Split(Trim(Text1.Text), ",")
For i = 0 To UBound(A)
If A(i) = "他" Then
HeN = HeN + 1
ElseIf A(i) = "你" Then
YouN = YouN + 1
ElseIf A(i) = "我" Then
MeN = MeN + 1
End If
Next
Text2.Text = ""
Text2.Text = "他" & HeN & "个" & vbCrLf & "你" & YouN & "个" & vbCrLf & "我" & MeN & "个"
End Sub
一般情况下“你,不1个”这种是不能设置的,除非你事先知道“你”和“不”的字数是一样的才可以这样显示。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private
Sub
Command1_Click()
Dim
w
As
Integer,
n
As
Integer,
t
As
Integer
'我你他的个数
For
i
=
1
To
Len(Text1)
Select
Case
Mid(Text1,
i,
1)
Case
"我"
w
=
w
+
1
Case
"你"
n
=
n
+
1
Case
"他"
t
=
t
+
1
End
Select
Next
Text2
=
"我"
&
w
&
"个,你"
&
n
&
"个,他"
&
t
&
"个"
End
Sub
Sub
Command1_Click()
Dim
w
As
Integer,
n
As
Integer,
t
As
Integer
'我你他的个数
For
i
=
1
To
Len(Text1)
Select
Case
Mid(Text1,
i,
1)
Case
"我"
w
=
w
+
1
Case
"你"
n
=
n
+
1
Case
"他"
t
=
t
+
1
End
Select
Next
Text2
=
"我"
&
w
&
"个,你"
&
n
&
"个,他"
&
t
&
"个"
End
Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询