求助!字符串提取单词
vb吧
全部回复
仅看楼主
level 8
tbzp666 楼主
在从一个英文短文中提取每个单词,并把单词的首字母大写
如短文:Upholding national sovereignty, security and development interests is the paramount principle in the policy. On the basis of this prerequisite, Hong Kong and Macao maintain their capitalist system over the long run and enjoy a high degree of autonomy, he noted.
输出为:
Upholding National Sovereignty Security And Development Interests Is
The Paramount Principle In The Policy On The
Basis Of This Prerequisite Hong Kong And Macao
Maintain Their Capitalist System Over The Long Run
And Enjoy A High Degree Of Autonomy He
Noted
2022年07月02日 02点07分 1
level 1
Private Sub Command1_Click()
Dim e1 As String, e2 As String, s1 As String, s2 As String, l As Integer
e1 = Text1.Text
l = Len(e1)
s2 = Mid(e1, 1, 1)
If Asc(s2) >= 97 And Asc(s2) <= 122 Then
e2 = Chr(Asc(s2) - 32)
Else
e2 = s2
End If
For i = 2 To l
s1 = s2
s2 = Mid(e1, i, 1)
If (Asc(s1) < 41 Or Asc(s1) > 90 And Asc(s1) < 97 Or Asc(s1) > 122) And Asc(s2) >= 97 And Asc(s2) <= 122 Then s2 = Chr(Asc(s2) - 32)
e2 = e2 + s2
Next i
Text2.Text = e2
End Sub
2022年07月04日 11点07分 2
level 11
2022年07月04日 12点07分 3
level 7
正则
2022年07月07日 00点07分 4
level 8
tbzp666 楼主
标点没有办法去掉
2022年07月08日 01点07分 5
你的要求里没说去掉标点啊,虽然示例结果里去掉了标点但谁会仔细看啊
2022年07月08日 06点07分
难怪你说“提取”单词啊,原来是只要单词不要标点啊,输出结果里的空格只是为了区分每个单词是么
2022年07月08日 06点07分
是的
2022年07月08日 07点07分
level 15
2022年07月08日 07点07分 8
[大拇指][大拇指][大拇指][大拇指]
2022年07月09日 11点07分
level 8
tbzp666 楼主
有一道类似的题目:
设计一个程序,不管输入的文字是大写还是小写,或大小写任意混合,都能将其整理成除每个句子开头字母是大写外,其他都是小写字母
Dim StrL$, s$, e$
e = "空格 "
StrL = "as a Matter of Fact,He was tired.why? this ervening had tired him! he gazed THE door.anger!miserable!"
c = UCase(Mid(StrL, 1, 1))
s = s & c
For i = 2 To Len(StrL)
c = Mid(StrL, i, 1)
If (c >= "a" And c <= "z") Or (c >= "A" And c <= "Z") Then
If InStr(1, ".?!", e) > 0 Then
If c >= "a" Then c = UCase(c)
Else
If c <= "Z" Then c = LCase(c)
End If
End If
s = s & c
If c <> "空格" Then e = c
Next
Print s
2022年07月10日 08点07分 9
1