统计字符StatisticsCharacter

来自中国的朋友,欢迎您在本版面使用中文讨论问题。请注意,如果您想得到不懂中文的人的帮助,请同时提供英文译文。
Help and discussions in Chinese.
Post Reply
liqi98136
Posts: 53
Joined: Sun Jan 17, 2010 11:37 pm

统计字符StatisticsCharacter

Post by liqi98136 »

Code: Select all

import "ecere"

class Form1 : Window
{
   text = "Form1";
   background = activeBorder;
   borderStyle = fixed;
   hasMinimize = true;
   hasClose = true;
   size = { 576, 432 };
   anchor = { horz = -3, vert = -12 };



   Button button1 
   {
      label1, this, "统计", position = { 24, 336 };

      bool NotifyClicked(Button button, int x, int y, Modifiers mods)
      {
          int Eng_count,Chn_count;
          int Spa_count;
          int Letter,Eng_word;
          int Lines_count,Cols_ount;
          int i,j;
          String s;

          EditLine tempLine;

          Eng_count=0;  //英文字符
          Chn_count=0;  //汉字
          Spa_count=0;  //空格
          Letter=0;     //连续英文字母控制开关
          Eng_word=0;   //英文字母


          Lines_count=editBox1.numLines; 
          

          for (i=0;i<Lines_count;i++)
          {
           editBox1.GoToLineNum(i);
           Cols_ount=editBox1.line.count;
           s=editBox1.line.text;
           for  (j=0; j <= Cols_ount ;j++)        
              {
               char ch;
               ch=s[j];

               if(ch>=33 && ch <=128) {Eng_count++;}
               else if(ch>=129 || ch <0) {Chn_count++;}
               else if(ch==32) {Spa_count++;}
              
               if((ch>=95 && ch<=90)||(ch>=97 && ch<=122))
               {
                 Letter++;
               }
               else
               {
                 if(Letter>0)
                    Eng_word++;
                 Letter=0;
               }
              }
          }
          
          L_chn.text=PrintString(Chn_count / 3);
          L_eng.text=PrintString(Eng_word);
          L_char1.text=PrintString(Eng_count);
          L_char2.text=PrintString(Eng_count+Spa_count);
          L_line.text=PrintString(Lines_count);
         return true;
      }
   };
   Button button2 
   {      
      label1, this, "退出", position = { 88, 336 };

      bool NotifyClicked(Button button, int x, int y, Modifiers mods)
      {
         Destroy(0);
         
         return true;
      }
   };
   EditBox editBox1 { this, text = "editBox1", size = { 390, 379 }, position = { 16, 16 }, hasHorzScroll = true, true, multiLine = true };
   Label label1 { this, text = "统计区", inactive = false, size = { 140, 381 }, position = { 416, 16 }, isGroupBox = true }; 
   Label label2 { label1, this, text="汉字:", position = { 16, 32 } }; 
   Label L_chn { label1, this, text="0", size = { 52, 13 }, position = { 40, 56 } }; 
   Label label4 { label1, this, text="英文单词:", position = { 16, 88 } }; 
   Label L_eng { label1, this, text="0", position = { 40, 120 } }; 
   Label label6 { label1, this, text="字符(不计空格):", position = { 16, 152 } };  
   Label L_char1 { label1, this, text="0", position = { 48, 176 } };
   Label label8 { label1, this, text="字符(计空格):", position = { 24, 208 } }; 
   Label L_char2 {label1,  this, text="0", position = { 48, 232 } };
   Label label10 { label1, this, text="行数:", position = { 16, 256 } };
   Label L_line {  label1, this, text="0", position = { 48, 288 } }; 
}

Form1 form1 {};
haijenny
Posts: 2
Joined: Tue Mar 16, 2010 9:23 pm

Re: 统计字符StatisticsCharacter

Post by haijenny »

8-) 收起
Post Reply