本文整理匯總了C#中Nikse.SubtitleEdit.Core.Subtitle.GetIndex方法的典型用法代碼示例。如果您正苦於以下問題:C# Subtitle.GetIndex方法的具體用法?C# Subtitle.GetIndex怎麽用?C# Subtitle.GetIndex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Nikse.SubtitleEdit.Core.Subtitle
的用法示例。
在下文中一共展示了Subtitle.GetIndex方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: GeneratePreview
public void GeneratePreview(Subtitle subtitle, List<ReplaceExpression> replaceRules)
{
var fixedSubtitle = new Subtitle(subtitle);
_previewItems = new List<PreviewItem>();
FixCount = 0;
var replaceExpressions = new HashSet<ReplaceExpression>();
foreach (var item in replaceRules)
{
if (item.Checked)
{
string findWhat = item.FindWhat;
if (!string.IsNullOrEmpty(findWhat)) // allow space(s)
{
replaceExpressions.Add(item);
if (item.SearchType == SearchTypeRegularExpression && !_compiledRegExList.ContainsKey(findWhat))
{
_compiledRegExList.Add(findWhat, new Regex(findWhat, RegexOptions.Compiled | RegexOptions.Multiline));
}
}
}
}
foreach (Paragraph p in subtitle.Paragraphs)
{
bool hit = false;
string newText = p.Text;
foreach (ReplaceExpression item in replaceExpressions)
{
if (item.SearchType == SearchTypeCaseSensitive)
{
if (newText.Contains(item.FindWhat))
{
hit = true;
newText = newText.Replace(item.FindWhat, item.ReplaceWith);
}
}
else if (item.SearchType == SearchTypeRegularExpression)
{
Regex r = _compiledRegExList[item.FindWhat];
if (r.IsMatch(newText))
{
hit = true;
newText = r.Replace(newText, item.ReplaceWith);
}
}
else
{
int index = newText.IndexOf(item.FindWhat, StringComparison.OrdinalIgnoreCase);
if (index >= 0)
{
hit = true;
do
{
newText = newText.Remove(index, item.FindWhat.Length).Insert(index, item.ReplaceWith);
index = newText.IndexOf(item.FindWhat, index + item.ReplaceWith.Length, StringComparison.OrdinalIgnoreCase);
}
while (index >= 0);
}
}
}
if (hit && newText != p.Text)
{
FixCount++;
_previewItems.Add(new PreviewItem(p.ID, true, p.Number.ToString(), p.Text, newText));
int index = subtitle.GetIndex(p);
fixedSubtitle.Paragraphs[index].Text = newText;
}
}
_previewBox.Title = string.Format(Configuration.Settings.Language.MultipleReplace.LinesFoundX, FixCount);
ShowPreview(_previewItems);
}