| 网站首页 | 业界新闻 | 群组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
乐学 会学 多求 善思千里之行 始于足下
共有 493 人关注过本帖
标题:怎么统计字符串中的相同字母个数
只看楼主 加入收藏
zkzcs
Rank: 1
等 级:新手上路
帖 子:17
专家分:5
注 册:2005-9-25
结帖率:100%
  已结贴   问题点数:20  回复次数:10   
怎么统计字符串中的相同字母个数
请问这个怎么实现
每一行是一个班级zifu中1-5字母是语文老师各项得分
6-10字母是数学老师各项得分
11-15字母是外语老师得分
统计出各位老师的得分A10分 B9分 C8分 D7分
附件: 您没有浏览附件的权限,请 登录注册
2019-01-23 12:04
zkzcs
Rank: 1
等 级:新手上路
帖 子:17
专家分:5
注 册:2005-9-25
  得分:0 
麻烦老师出手相助谢谢!
2019-01-23 12:05
红星二锅头
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:41
帖 子:461
专家分:695
注 册:2016-8-25
  得分:0 
用 Substr() 函数,,,

团队红星二锅头,队长王猛,领队李冲,顾问杨伟,副队张挺,外联马彪,内勤韩秀,人事顾闯,财务赵魁,后勤周强
2019-01-23 13:22
jyxfp
Rank: 2
等 级:论坛游民
帖 子:22
专家分:71
注 册:2013-2-9
  得分:2 
Select *,Len(Chrtran(zifu," ",""))-Len(Chrtran(zifu,"A ","")) As A,;
  LEN(Chrtran(zifu," ",""))-Len(Chrtran(zifu,"B ","")) As B,;
  LEN(Chrtran(zifu," ",""))-Len(Chrtran(zifu,"C ","")) As C,;
  LEN(Chrtran(zifu," ",""))-Len(Chrtran(zifu,"D ","")) As D;
  FROM 表
2019-01-23 16:18
cyl8273
Rank: 1
等 级:新手上路
帖 子:10
专家分:5
注 册:2010-5-21
  得分:2 
CLEAR
fz='a10b09c08d07'
ls='语文数学外语'

zhifu='aaddcdadbbabbbc'

FOR i=1 TO 15 STEP 5
    vz = SUBSTR(zhifu,i,5)
    jg = 0
    FOR j=1 TO 12 STEP 3
        zz  = SUBSTR(fz,j,1)
        zzz = VAL(SUBSTR(fz,j+1,2))
        jg = jg +(LEN(vz)-len(CHRTRAN(vz,zz,'')))*zzz
    ENDFOR
    ?SUBSTR(ls,((i-1)/5)*4+1,4)+":"+STR(jg,4)  
ENDFOR  
2019-01-23 16:47
csyx
Rank: 4
等 级:业余侠客
威 望:6
帖 子:46
专家分:208
注 册:2018-3-13
  得分:4 
Select Cast(banji as N(10)) as banji, zifu from 源表 into cursor temp
Copy To temp.txt sdf
Use in Select('源表')
Use in Select('temp')

*-- 拆分成1+15个字段
cFlds = 'banji N(10)'
For i = 1 to 15
    cFlds = cFlds + Textmerge(',f<<i>> C(1)')
EndFor
Create Cursor temp (&cFlds)
Append From temp.txt sdf
Erase temp.txt

cSql = ''
For i = 1 to 3
    cName = ICase(i==1, '语文', i==2, '数学', '外语') + '老师'
    For j = 1 to 5
        If i == 1 and j == 1
            c1 = ''
        Else
            c1 = ' union all'
        EndIf
        Text to c1 Noshow textmerge pretext 1+2+4+8
            <<c1>> select '<<cName>>' 老师,f<<j+(i-1)*5>> 分数,count(*) 个数 from temp group by 老师,分数
        EndText
        cSql = cSql + c1
    EndFor
EndFor
Text to cSql Noshow textmerge pretext 1+2+4+8
    Select 老师,分数,Sum(个数) 个数 from (<<cSql>>) a group by 老师,分数
EndText
&cSql
2019-01-23 21:18
sdta
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:176
帖 子:7508
专家分:18004
注 册:2012-2-5
  得分:8 
程序代码:
CLOSE DATABASES ALL
cZdm = "Kh C(9)"
FOR nCnt = 1 TO 15
    cZdm = cZdm + ", " + "Zd" + PADL(nCnt, 2, "0") + " N(4)"
ENDFOR
CREATE CURSOR tjb (&cZdm)
USE 全体 IN 0 ALIAS qt
SELECT qt
SCAN
    LOCAL aSj[16]
    aSj = 0
    aSj[1] = qt.Kh
    FOR nCnt = 2 TO 16
        DO CASE
            CASE BETWEEN(nCnt, 2, 15)
                cStr = SUBSTR(da1, (nCnt-2) * 5 + 1 ,5)
            OTHERWISE
                cStr = SUBSTR(da1, 71 ,10)
        ENDCASE
        FOR ii = 1 TO LEN(cStr)
            cStr1 = SUBSTR(cStr, ii, 1)
            aSj[nCnt] = aSj[nCnt] + ICASE(cStr1 == "A", 10,cStr1 == "B", 9,cStr1 == "C", 8,cStr1 == "D", 7, 0)
        ENDFOR
    ENDFOR
    INSERT INTO tjb FROM ARRAY aSj
ENDSCAN
SELECT tjb
BROWSE


[此贴子已经被作者于2019-1-23 23:33编辑过]


坚守VFP最后的阵地
2019-01-23 23:30
wengjl
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:67
帖 子:1501
专家分:2712
注 册:2007-4-27
  得分:1 
? occurs('A','ABCDBACDAAABADC')

只求每天有一丁点儿的进步就可以了
2019-01-24 08:35
wengjl
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:67
帖 子:1501
专家分:2712
注 册:2007-4-27
  得分:3 
  CLOSE DATABASES
  
  SELECT 0
  USE pjtj alia kg
  SCAN
    _yw=SUBSTR(kg.zifu,1,5)
    _sx=SUBSTR(kg.zifu,6,5)
    _yy=SUBSTR(kg.zifu,11,5)
    REPLACE yw with OCCURS('A',_yw)*10+OCCURS('B',_yw)*9+OCCURS('C',_yw)*8+OCCURS('D',_yw)*7
    REPLACE sx with OCCURS('A',_sx)*10+OCCURS('B',_sx)*9+OCCURS('C',_sx)*8+OCCURS('D',_sx)*7
    REPLACE yy with OCCURS('A',_yy)*10+OCCURS('B',_yy)*9+OCCURS('C',_yy)*8+OCCURS('D',_yy)*7   
    SELECT kg
  ENDSCAN

表中加三个字段:yw(语文) sx(数学) yy(英语)

只求每天有一丁点儿的进步就可以了
2019-01-24 08:56
zkzcs
Rank: 1
等 级:新手上路
帖 子:17
专家分:5
注 册:2005-9-25
  得分:0 
非常感谢各位老师的热心帮助,问题解决了。再次感谢,谢谢!
2019-01-24 16:36







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

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