标题:求助,请问怎么统计一段英文里首字母出现的次数
只看楼主
a88088
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2021-1-7
结帖率:0
已结贴  问题点数:20 回复次数:3 
求助,请问怎么统计一段英文里首字母出现的次数
要统计一段英文里首字母出现的次数,怎么做?下面这种的,
例如:Cryopreservation is the most efficient method for long-term preservation of mammalian sperm. However, freeze-thawing procedures may strongly impair the sperm function and survival and thus decrease the reproductive performance.
本段单词首字母出现次数:A:2 C:1 D:1 E:1 F:3 H:1 I:2 L:1 M:4 O:1 P:3 R:1 S:4 T:4
搜索更多相关主题的帖子: 字母 英文 次数 出现 统计 
2021-01-07 22:46
厨师王德榜
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:183
帖 子:942
专家分:4724
注 册:2013-2-16
得分:10 
单词与单词之间一般是空格来分隔的,那么这一段话可以用split()先分割了,结果保存到一个数组。
遍历这个数组,找出数组中每项的首字母,再配合一个字典,就能获得了。
现在没时间写,不过,代码也很简单,你自己先摸索一下。
2021-01-07 23:16
hbra000
Rank: 2
等 级:论坛游民
帖 子:1
专家分:10
注 册:2021-1-14
得分:10 
Function test(rg As Range) As String  '自定义公式 test ,选定单元格
    Dim d As Object
    Set d = CreateObject("scripting.dictionary")
    Dim arr
   
    arr = Split(Trim(rg), " ")
   
    Dim i As Long
    For i = 0 To UBound(arr)
        If Len(arr(i)) >= 1 Then
            d(UCase(Left(arr(i), 1))) = d(UCase(Left(arr(i), 1))) + 1
        End If
    Next i
   
    Erase arr
    If d.Count > 0 Then
        arr = d.keys
        For i = 0 To d.Count - 1
            If arr(i) <> " " Then
                test = test & " " & arr(i) & ":" & d(arr(i))
            End If
        Next i
    End If
    test = Right(test, Len(test) - 1)
End Function
2021-01-14 20:40
sdta
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:江苏省连云港市
等 级:版主
威 望:323
帖 子:9621
专家分:26174
注 册:2012-2-5
得分:0 
VFP CODE
程序代码:
CLEAR
TEXT TO lcStr NOSHOW TEXTMERGE
Cryopreservation is the most efficient method for long-term preservation of mammalian sperm. However, freeze-thawing procedures may strongly impair the sperm function and survival and thus decrease the reproductive performance.
ENDTEXT
ALINES(laStr, lcStr, 4 + 1, SPACE(1), ",", ".")
LOCAL la[26]
la = 0
FOR lnJ = 1 TO ALINES(laStr, lcStr, 4 + 1, SPACE(1), ",", ".")
    ln = ASC(PROPER(LEFT(laStr[lnJ], 1))) - 64
    la[ln] = la[ln] + 1
ENDFOR 
FOR lnJ = 1 TO 26
    IF la[lnJ] > 0
        ? SPACE(5) + CHR(lnj + 64), la[lnj]
    ENDIF
ENDFOR




[此贴子已经被作者于2021-4-13 22:10编辑过]


坚守VFP最后的阵地
2021-04-13 22:09



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-504565-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.264843 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved