统计单词数量

 

复制代码
(defun count-words-region (beginning end)
  "Print number of words in the region."
  (interactive "r")
  (message "Counting words in region ... ")
  (save-excursion
    (let ((count 0))
        (goto-char beginning)
        
        (while (and (< (point) end) (re-search-forward "\\w+\\W*" end t))
            (setq count (1+ count)))
            
        (cond ((zerop count)
               (message "The region does NOT have any words."))
              
              ((= 1 count)
               (message "The region has 1 word."))
               
              (t
               (message "The region has %d words." count))))))
复制代码

 

posted @   WendellYih  阅读(267)  评论(0编辑  收藏  举报
编辑推荐:
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
阅读排行:
· Ollama——大语言模型本地部署的极速利器
· 使用C#创建一个MCP客户端
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· Windows编程----内核对象竟然如此简单?
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
点击右上角即可分享
微信分享提示