🛠️ToolsShed

字数和字符统计

统计文本中的单词、字符、句子和段落数。

0
单词数
0
字符数
0
字符数(不含空格)
0
句子数
0
段落数
1
行数
约 1 分钟
阅读时间

字数统计工具分析您的文本,即时报告单词数、字符数(含/不含空格)、句子数和段落数。无论是撰写推文、填写大学申请文章、满足期刊投稿字数限制,还是撰写有字符限制的广告文案,对于在特定长度限制内工作的任何人来说,这都是必不可少的写作辅助工具。

将文本粘贴或输入到输入区域,计数会在您写作时实时更新。该工具还根据成人平均阅读速度(每分钟 200-250 个单词)估算阅读时间,对博客文章、演示文稿和演讲非常有用。

字数和字符数因计数方式不同而略有差异。该工具遵循文字处理软件最常用的规则:连续的非空白字符构成一个单词,空白分隔单词。

常见问题

代码实现

def count_text(text: str) -> dict:
    words = text.split()
    chars_with_spaces = len(text)
    chars_no_spaces = len(text.replace(" ", "").replace("\n", "").replace("\t", ""))
    sentences = len([s for s in text.replace("!", ".").replace("?", ".").split(".") if s.strip()])
    paragraphs = len([p for p in text.split("\n\n") if p.strip()])
    reading_time_min = round(len(words) / 225, 1)  # ~225 wpm average

    return {
        "words": len(words),
        "chars_with_spaces": chars_with_spaces,
        "chars_no_spaces": chars_no_spaces,
        "sentences": sentences,
        "paragraphs": paragraphs,
        "reading_time_min": reading_time_min,
    }


text = """Hello world. This is a sample paragraph.

This is the second paragraph with more words and sentences!"""

stats = count_text(text)
for key, value in stats.items():
    print(f"{key}: {value}")

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.