| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1116 人关注过本帖
标题:方法定义出错?????
只看楼主 加入收藏
yhlvht
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:36
帖 子:707
专家分:4405
注 册:2011-9-30
收藏
得分:0 
public class textualEdit
    {
        public string str = " ";   //存储一页文章
        public string s;           // 统计在文章中要查的重复的字符串
        public string st;          //  要删除的字符串

        public int count(string str)       //统计文章总字数
        {
            this.str = str;
            int Count = 0;
            Count = str.Length;
            return Count;

        }

        public int blankSpace(string str)       //统计在文章中出现空格个数
        {
            this.str = str;
            string Del = str.Replace(" ", "");
            return str.Length - Del.Length;
        }

        public int repeat(string str, string s)       //统计某个字符串在文章中出现的次数
        {
            int count3 = str.Length;
            string dstr = Dele(str, s);
            return (count3 - dstr.Length) / s.Length;

        }

        public int amount(string str)       //统计在文章中出现数字个数
        {
            this.str = str;
            char[] cara = str.ToCharArray();
            var ch1 = Array.FindAll(cara, x => char.IsDigit(x));
            return ch1.Length;
        }

        public string Dele(string str, string st)        //文章中要删除的某一子串
        {
            this.str = str;
            this.st = st;
            string Del = str.Replace(st, "");
            return Del;
        }

    }
2013-06-20 15:14
吾心无待
Rank: 2
等 级:论坛游民
帖 子:8
专家分:11
注 册:2013-6-20
收藏
得分:0 
1.统计字符串出现的次数建议使用IndexOf方法。
int startIndex,count = 0;
int textLength = str.Length;
int sLength = s.Length;
while(startIndex<textLength)
{
    int find=str.IndexOf(s,startIndex);
    if(find!=-1)count++;
    startIndex = find+sLength;
}
return count;
2.
2013-06-20 20:30
吾心无待
Rank: 2
等 级:论坛游民
帖 子:8
专家分:11
注 册:2013-6-20
收藏
得分:0 
回复 10楼 yhlvht
想法很好实现不易。。。。string.Replace方法是不允许第二个参数为空串的。
2013-06-20 20:32
吾心无待
Rank: 2
等 级:论坛游民
帖 子:8
专家分:11
注 册:2013-6-20
收藏
得分:0 
记错了。string.Replace方法是不允许第一个参数为空串的,第二个是可以空的。
2013-06-20 20:34
快速回复:方法定义出错?????
数据加载中...
 
   



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

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