qq_28144595
爱说谎的团子
2015-11-14 17:19

为什么最后一个for语句里的截取字符语句总是出错,大神们帮帮忙啊。。

  • c#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TJ
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

    private void Form1_Load(object sender, EventArgs e)
    {

    }
    public int Pd(string s)
    {
        int len = s.Length;
        //s=str.Substring(str.Length-i); // or str=str.Remove(0,str.Length-i); k = k.Substring(k.Length-1, 1);
       // string str = s.Substring(s.Length -1,1);
        //s = s.Remove(s.LastIndexOf(","), 1);
       /* if (str==","||str==".")
        {
            s = s.Remove(s.Length - 2,s.Length -1);
        }*/
        ListViewItem li = new ListViewItem();
        for (int i = 0; i < listView1.Items.Count; i++)
        {
            if (listView1.Items[i].SubItems[0].Text == s)
            {
                return 0;
            }
        }
        return 1;
    }
    public int Pdc(string[] sj,string s)
    {
        int tem=0;
        for (int i = 0; i < sj.Length; i++)
        {
            if (s == sj[i])
                tem++;
        }
        return tem;
    }

    private void button1_Click(object sender, EventArgs e)
    {
        string center = txtDate.Text;
        string str = center.ToLower();
        string[] parm = str.Split(' ');
        int len = parm.Length;
        this.listView1.View = View.Details;
        this.listView1.GridLines = true;
        this.listView1.HeaderStyle = ColumnHeaderStyle.Nonclickable;
        this.listView1.Columns.Add("词汇", 120, HorizontalAlignment.Right);
        this.listView1.Columns.Add("出现次数", 120, HorizontalAlignment.Right);
        this.listView1.Visible = true;

        for (int i = 0; i < len; i++)
        {
            string s = parm[i];

            s = s.Remove(s.LastIndexOf(","), 1); 

            int tem = Pd(parm[i]);
            if (tem == 1 && parm[i] != "")
            {
                int m = Pdc(parm, parm[i]);
                string mm = Convert.ToString(m);
                ListViewItem li = new ListViewItem();
                li.SubItems[0].Text = parm[i].ToString();
                li.SubItems.Add(mm);
                this.listView1.Items.Add(li);
            }
        }
        } 
    }

}

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

4条回答