mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2025-01-31 13:01:39 +01:00
Word counter now acts more like the word counter in MS Word - thx Barbara :)
This commit is contained in:
parent
f0c13c2236
commit
652844dc2b
@ -150,8 +150,7 @@ namespace Nikse.SubtitleEdit.Core
|
||||
{
|
||||
if (string.IsNullOrEmpty(Text))
|
||||
return 0;
|
||||
int wordCount = HtmlUtil.RemoveHtmlTags(Text, true).Split(new[] { ' ', ',', '.', '!', '?', ';', ':', '(', ')', '[', ']', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries).Length;
|
||||
return (60.0 / Duration.TotalSeconds) * wordCount;
|
||||
return (60.0 / Duration.TotalSeconds) * Text.CountWords();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -90,6 +90,11 @@ namespace Nikse.SubtitleEdit.Core
|
||||
return source.Replace("\r\r\n", "\n").Replace("\r\n", "\n").Replace('\r', '\n').Replace('\u2028', '\n').Split('\n');
|
||||
}
|
||||
|
||||
public static int CountWords(this string source)
|
||||
{
|
||||
return HtmlUtil.RemoveHtmlTags(source, true).Split(new[] { ' ', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries).Length;
|
||||
}
|
||||
|
||||
// http://www.codeproject.com/Articles/43726/Optimizing-string-operations-in-C
|
||||
public static int FastIndexOf(this string source, string pattern)
|
||||
{
|
||||
|
@ -179,7 +179,6 @@ https://github.com/SubtitleEdit/subtitleedit
|
||||
foreach (string word in text.Split(ExpectedChars, StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
var s = word.Trim();
|
||||
_totalWords++;
|
||||
if (s.Length > 1 && hashtable.ContainsKey(s))
|
||||
{
|
||||
hashtable[s]++;
|
||||
@ -243,7 +242,10 @@ https://github.com/SubtitleEdit/subtitleedit
|
||||
var hashtable = new Dictionary<string, int>();
|
||||
|
||||
foreach (Paragraph p in _subtitle.Paragraphs)
|
||||
{
|
||||
MostUsedWordsAdd(hashtable, p.Text);
|
||||
_totalWords += p.Text.CountWords();
|
||||
}
|
||||
|
||||
var sortedTable = new SortedDictionary<string, string>();
|
||||
foreach (KeyValuePair<string, int> item in hashtable)
|
||||
|
Loading…
x
Reference in New Issue
Block a user