本文整理汇总了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);
}