本文整理汇总了C#中StripableText.Substring方法的典型用法代码示例。如果您正苦于以下问题:C# StripableText.Substring方法的具体用法?C# StripableText.Substring怎么用?C# StripableText.Substring使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StripableText
的用法示例。
在下文中一共展示了StripableText.Substring方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RemoveColon
public string RemoveColon(string text)
{
if (!Settings.RemoveTextBeforeColon)
return text;
if (text.IndexOf(":", StringComparison.Ordinal) < 0)
return text;
// House 7x01 line 52: and she would like you to do three things:
// Okay or remove???
if (text.IndexOf(':') > 0 && text.IndexOf(':') == text.Length - 1 && text != text.ToUpper())
return text;
string newText = string.Empty;
string[] parts = text.Trim().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
int noOfNames = 0;
int count = 0;
bool removedInFirstLine = false;
bool removedInSecondLine = false;
foreach (string s in parts)
{
int indexOfColon = s.IndexOf(":", StringComparison.Ordinal);
if (indexOfColon > 0)
{
string pre = s.Substring(0, indexOfColon);
if (Settings.RemoveTextBeforeColonOnlyUppercase && pre.Replace("<i>", string.Empty) != pre.Replace("<i>", string.Empty).ToUpper())
{
newText = newText + Environment.NewLine + s;
newText = newText.Trim();
}
else
{
StripableText st = new StripableText(pre);
if (count == 1 && Utilities.CountTagInText(text, Environment.NewLine) == 1 && removedInFirstLine && Utilities.CountTagInText(s, ":") == 1 &&
!newText.EndsWith('.') && !newText.EndsWith('!') && !newText.EndsWith('?') && !newText.EndsWith(".</i>") && !newText.EndsWith("!</i>") && !newText.EndsWith("?</i>") &&
s != s.ToUpper())
{
if (pre.Contains("<i>") && s.Contains("</i>"))
newText = newText + Environment.NewLine + "<i>" + s;
else if (pre.Contains("<b>") && s.Contains("</b>"))
newText = newText + Environment.NewLine + "<b>" + s;
else if (pre.Contains('[') && s.Contains(']'))
newText = newText + Environment.NewLine + "[" + s;
else if (pre.Contains('(') && s.EndsWith(')'))
newText = newText + Environment.NewLine + "(" + s;
else
newText = newText + Environment.NewLine + s;
}
else if (count == 1 && Utilities.CountTagInText(text, Environment.NewLine) == 1 && indexOfColon > 15 && s.Substring(0, indexOfColon).Contains(' ') && Utilities.CountTagInText(s, ":") == 1 &&
!newText.EndsWith('.') && !newText.EndsWith('!') && !newText.EndsWith('?') && !newText.EndsWith(".</i>") && !newText.EndsWith("!</i>") && !newText.EndsWith("?</i>") &&
s != s.ToUpper())
{
if (pre.Contains("<i>") && s.Contains("</i>"))
newText = newText + Environment.NewLine + "<i>" + s;
else if (pre.Contains("<b>") && s.Contains("</b>"))
newText = newText + Environment.NewLine + "<b>" + s;
else if (pre.Contains('[') && s.Contains(']'))
newText = newText + Environment.NewLine + "[" + s;
else if (pre.Contains('(') && s.EndsWith(')'))
newText = newText + Environment.NewLine + "(" + s;
else
newText = newText + Environment.NewLine + s;
}
else if (Utilities.CountTagInText(s, ":") == 1)
{
bool remove = true;
if (indexOfColon > 0 && indexOfColon < s.Length - 1)
{
if ("1234567890".Contains(s.Substring(indexOfColon - 1, 1)) && "1234567890".Contains(s.Substring(indexOfColon + 1, 1)))
remove = false;
}
if (s.StartsWith("Previously on") || s.StartsWith("<i>Previously on"))
remove = false;
if (remove && Settings.ColonSeparateLine)
{
if (indexOfColon == s.Length - 1 || s.Substring(indexOfColon + 1).StartsWith(Environment.NewLine))
remove = true;
else
remove = false;
}
if (remove)
{
string content = s.Substring(indexOfColon + 1).Trim();
if (content.Length > 0)
{
if (pre.Contains("<i>") && content.Contains("</i>"))
newText = newText + Environment.NewLine + "<i>" + content;
else if (pre.Contains("<b>") && content.Contains("</b>"))
newText = newText + Environment.NewLine + "<b>" + content;
else if (pre.Contains('[') && content.Contains(']'))
newText = newText + Environment.NewLine + "[" + content;
else if (pre.Contains('(') && content.EndsWith(')'))
newText = newText + Environment.NewLine + "(" + content;
else
newText = newText + Environment.NewLine + content;
if (count == 0)
removedInFirstLine = true;
//.........这里部分代码省略.........
示例2: RemoveColon
public string RemoveColon(string text)
{
if (!Settings.RemoveTextBeforeColon || text.IndexOf(':') < 0)
return text;
string preAssTag = string.Empty;
if (text.StartsWith("{\\", StringComparison.Ordinal) && text.IndexOf('}') > 0)
{
int indexOfEndBracket = text.IndexOf('}') + 1;
preAssTag = text.Substring(0, indexOfEndBracket);
text = text.Remove(0, indexOfEndBracket).TrimStart();
}
// House 7x01 line 52: and she would like you to do three things:
// Okay or remove???
var noTagText = HtmlUtil.RemoveHtmlTags(text);
if (noTagText.IndexOf(':') > 0 && noTagText.IndexOf(':') == noTagText.Length - 1 && noTagText != noTagText.ToUpper() && noTagText.Length > 10)
return text;
string newText = string.Empty;
var lines = text.Trim().SplitToLines();
int noOfNames = 0;
int count = 0;
bool removedInFirstLine = false;
bool removedInSecondLine = false;
foreach (string line in lines)
{
int indexOfColon = line.IndexOf(':');
if (indexOfColon > 0 && IsNotInsideBrackets(line, indexOfColon))
{
var pre = line.Substring(0, indexOfColon);
var noTagPre = HtmlUtil.RemoveHtmlTags(pre, true);
if (Settings.RemoveTextBeforeColonOnlyUppercase && noTagPre != noTagPre.ToUpper())
{
newText = (newText + Environment.NewLine + line).Trim();
}
else
{
var st = new StripableText(pre);
if (count == 1 && newText.Length > 1 && removedInFirstLine && Utilities.CountTagInText(line, ':') == 1 &&
".?!".IndexOf(newText[newText.Length - 1]) < 0 && newText.LineEndsWithHtmlTag(true) &&
line != line.ToUpper())
{
if (pre.Contains("<i>") && line.Contains("</i>"))
newText = newText + Environment.NewLine + "<i>" + line;
else if (pre.Contains("<b>") && line.Contains("</b>"))
newText = newText + Environment.NewLine + "<b>" + line;
else if (pre.Contains("<u>") && line.Contains("</u>"))
newText = newText + Environment.NewLine + "<u>" + line;
else if (pre.Contains('[') && line.Contains(']'))
newText = newText + Environment.NewLine + "[" + line;
else if (pre.Contains('(') && line.EndsWith(')'))
newText = newText + Environment.NewLine + "(" + line;
else
newText = newText + Environment.NewLine + line;
}
else if (count == 1 && newText.Length > 1 && indexOfColon > 15 && line.Substring(0, indexOfColon).Contains(' ') && Utilities.CountTagInText(line, ':') == 1 &&
".?!".IndexOf(newText[newText.Length - 1]) < 0 && newText.LineEndsWithHtmlTag(true) &&
line != line.ToUpper())
{
if (pre.Contains("<i>") && line.Contains("</i>"))
newText = newText + Environment.NewLine + "<i>" + line;
else if (pre.Contains("<b>") && line.Contains("</b>"))
newText = newText + Environment.NewLine + "<b>" + line;
else if (pre.Contains("<u>") && line.Contains("</u>"))
newText = newText + Environment.NewLine + "<u>" + line;
else if (pre.Contains('[') && line.Contains(']'))
newText = newText + Environment.NewLine + "[" + line;
else if (pre.Contains('(') && line.EndsWith(')'))
newText = newText + Environment.NewLine + "(" + line;
else
newText = newText + Environment.NewLine + line;
}
else if (Utilities.CountTagInText(line, ':') == 1)
{
bool remove = true;
if (indexOfColon > 0 && indexOfColon < line.Length - 1)
{
remove = !Utilities.IsBetweenNumbers(line, indexOfColon);
}
if (!DoRemove(pre))
remove = false;
if (remove && Settings.ColonSeparateLine)
{
if (indexOfColon == line.Length - 1 || line.Substring(indexOfColon + 1).StartsWith(Environment.NewLine, StringComparison.Ordinal))
remove = true;
else
remove = false;
}
if (remove)
{
var content = line.Substring(indexOfColon + 1).Trim();
if (content.Length > 0)
{
if (pre.Contains("<i>") && content.Contains("</i>"))
newText = newText + Environment.NewLine + "<i>" + content;
else if (pre.Contains("<b>") && content.Contains("</b>"))
//.........这里部分代码省略.........