為什麼需要文字統計?
| 場景 |
需要的指標 |
| SEO 優化 |
字數、關鍵字密度、可讀性 |
| 內容定價 |
字數、閱讀時間 |
| 學術論文 |
字數(中英分別統計) |
| 社交媒體 |
字元數(限制 280/2000) |
| 翻譯報價 |
字數/詞數 |
中英文字數統計的差異
核心問題:中文沒有空格分詞
英文:Hello World → 2 個單詞(空格分隔)
中文:你好世界 → 4 個字(逐字計算)還是 2 個詞(你好/世界)?
三種統計方式
| 方式 |
演算法 |
"你好World" 的結果 |
適用場景 |
| 字元數 |
所有字元 |
7 |
社交媒體限制 |
| 字/詞數 |
中文按字,英文按詞 |
6(4 字 + 2 詞) |
內容定價、SEO |
| 位元組數 |
UTF-8 編碼長度 |
10(4×3 + 2×1) |
儲存空間 |
JavaScript 實作
function countText(text: string) {
// 移除零寬字元
const clean = text.replace(/[\u200B-\u200D\uFEFF]/g, '');
// 字元數
const charCount = clean.replace(/\s/g, '').length;
// 中文字數
const chineseChars = (clean.match(/[\u4e00-\u9fff]/g) || []).length;
// 英文詞數
const englishWords = (clean.match(/[a-zA-Z]+/g) || []).length;
// 數字組數
const numbers = (clean.match(/\d+/g) || []).length;
// 總字/詞數
const wordCount = chineseChars + englishWords + numbers;
// 位元組數(UTF-8)
const byteCount = new TextEncoder().encode(clean).length;
// 行數
const lineCount = clean.split(/\n/).filter(l => l.trim()).length;
// 段落數
const paragraphCount = clean.split(/\n\s*\n/).filter(p => p.trim()).length;
return {
charCount,
wordCount,
chineseChars,
englishWords,
numbers,
byteCount,
lineCount,
paragraphCount,
};
}
閱讀時間估算
計算公式
中文閱讀速度:約 500 字/分鐘
英文閱讀速度:約 200-250 詞/分鐘
閱讀時間 = 中文字數 / 500 + 英文詞數 / 225
實作
function estimateReadingTime(text: string) {
const chineseChars = (text.match(/[\u4e00-\u9fff]/g) || []).length;
const englishWords = (text.match(/[a-zA-Z]+/g) || []).length;
const minutes = chineseChars / 500 + englishWords / 225;
if (minutes < 1) return '不到 1 分鐘';
if (minutes < 60) return `約 ${Math.ceil(minutes)} 分鐘`;
const hours = Math.floor(minutes / 60);
const mins = Math.ceil(minutes % 60);
return `約 ${hours} 小時 ${mins} 分鐘`;
}
不同內容的閱讀速度
| 內容類型 |
中文速度 |
英文速度 |
| 小說/散文 |
500-700 字/分 |
250-300 詞/分 |
| 技術文件 |
300-400 字/分 |
150-200 詞/分 |
| 法律檔案 |
200-300 字/分 |
100-150 詞/分 |
| 社交媒體 |
600-800 字/分 |
300+ 詞/分 |
關鍵字密度分析
什麼是關鍵字密度?
關鍵字密度 = 關鍵字出現次數 / 總詞數 × 100%
範例:
總詞數:500
「前端」出現 15 次
密度 = 15 / 500 × 100% = 3%
SEO 建議密度
| 密度 |
評價 |
| < 1% |
過低,搜尋引擎可能不重視 |
| 1-3% |
✅ 最佳範圍 |
| 3-5% |
偏高,注意自然度 |
| > 5% |
❌ 關鍵字堆砌,可能被懲罰 |
實作
function analyzeKeywordDensity(text: string, keyword: string) {
const regex = new RegExp(keyword, 'gi');
const occurrences = (text.match(regex) || []).length;
const chineseChars = (text.match(/[\u4e00-\u9fff]/g) || []).length;
const englishWords = (text.match(/[a-zA-Z]+/g) || []).length;
const totalWords = chineseChars + englishWords;
const density = (occurrences / totalWords) * 100;
return {
keyword,
occurrences,
totalWords,
density: density.toFixed(2) + '%',
evaluation: density < 1 ? '過低' : density <= 3 ? '最佳' : density <= 5 ? '偏高' : '堆砌',
};
}
文字可讀性評分
Flesch Reading Ease(英文)
分數 = 206.835 - 1.015 × (總詞數/總句數) - 84.6 × (總音節數/總詞數)
評分對照:
90-100 非常容易(5 年級)
60-70 標準(8-9 年級)
30-50 較難(大學生)
0-30 非常難(專業學術)
中文可讀性
中文沒有音節概念,通常用平均句長衡量:
function chineseReadability(text: string) {
const sentences = text.split(/[。!?;\n]/).filter(s => s.trim());
const chineseChars = (text.match(/[\u4e00-\u9fff]/g) || []).length;
const avgSentenceLength = chineseChars / sentences.length;
if (avgSentenceLength <= 15) return { score: '易讀', level: '大眾' };
if (avgSentenceLength <= 25) return { score: '適中', level: '標準' };
if (avgSentenceLength <= 40) return { score: '較難', level: '專業' };
return { score: '難讀', level: '學術' };
}
使用工具庫統計文字
- 開啟 字數統計工具
- 貼上或輸入文字
- 自動顯示:字元數、字/詞數、行數、段落數、閱讀時間
- 支援中英文混合統計
SEO 文案優化實戰
1. 標題長度
// Google 顯示約 60 個字元(30 個中文字)
function checkTitle(title: string) {
const length = title.length;
return {
length,
status: length <= 60 ? '✅' : '❌ 超過 60 字元',
};
}
2. 描述長度
// Google 顯示約 160 個字元(80 個中文字)
function checkDescription(desc: string) {
const length = desc.length;
return {
length,
status: length <= 160 ? '✅' : '❌ 超過 160 字元',
};
}
3. 正文長度
| 頁面類型 |
建議字數 |
| 部落格文章 |
1500-3000 字 |
| 產品頁面 |
300-800 字 |
| 首頁 |
300-500 字 |
| 教學 |
2000+ 字 |
4. 關鍵字分佈
✅ 好的分佈:
標題含關鍵字
第一段含關鍵字
正文自然出現 3-5 次
H2/H3 子標題含變體
❌ 壞的分佈:
每段都重複關鍵字
關鍵字與上下文無關
用隱藏文字堆砌
常見問題
Word 統計和線上工具統計不一致?
Word 的「字數」統計規則與線上工具可能不同:
- Word 2019+ 中文按「字」統計
- 部分工具中文按「字元」統計
- 建議統一使用一種工具,避免報價爭議
如何統計程式碼中的註解率?
function commentRate(code: string, language: string) {
const totalLines = code.split('\n').length;
let commentLines = 0;
if (language === 'javascript') {
const singleLineComments = (code.match(/\/\/.*/g) || []).length;
const multiLineComments = (code.match(/\/\*[\s\S]*?\*\//g) || []).length;
commentLines = singleLineComments + multiLineComments;
}
return (commentLines / totalLines * 100).toFixed(1) + '%';
}
總結
文字統計看似簡單,實則暗藏玄機——中英混合統計、閱讀時間估算、關鍵字密度分析各有講究。掌握這些指標,無論是 SEO 優化、內容定價還是翻譯報價,都能做到心中有數。工具庫的 字數統計工具 一鍵取得所有指標,讓你專注內容創作。