本文整理汇总了C#中StringBuilder.EndsWith方法的典型用法代码示例。如果您正苦于以下问题:C# StringBuilder.EndsWith方法的具体用法?C# StringBuilder.EndsWith怎么用?C# StringBuilder.EndsWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringBuilder
的用法示例。
在下文中一共展示了StringBuilder.EndsWith方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: JoinPath
public static string JoinPath(string root, string[] parts, int start, int count)
{
if (root == null)
throw new ArgumentNullException("root");
if (parts == null)
throw new ArgumentNullException("right");
if (start < 0 || start > parts.Length)
throw new ArgumentOutOfRangeException("start");
if (count < 0 || count > parts.Length - start)
throw new ArgumentOutOfRangeException("count");
var result = new StringBuilder(root.Trim());
var trimmed = parts.Skip(start).Take(count).Select(item => item.Trim());
foreach (var part in trimmed.Where(item => item.Any()))
// This seems complicated but the idea is to ensure the single separating slashes
// saving the slash appending operation if not necessary.
if (part.StartsWith('/')) {
if (result.Length > 0 && !result.EndsWith('/'))
result.Append(part);
else
result.Append(part, 1, part.Length - 1);
} else {
if (result.Length > 0 && !result.EndsWith('/'))
result.Append('/');
result.Append(part);
}
return result.ToString();
}
示例2: UpdateTest1
public void UpdateTest1()
{
StringBuilder str = new StringBuilder("[TestString]");
Assert.IsTrue(str.StartsWith("["));
Assert.IsTrue(str.EndsWith("]"));
Assert.AreEqual("TestString", str.UnBracketing(StringPair.SquareBracket).ToString());
}
示例3: StringBuilderExtensionEndsWith_OnCase_ReturnsTrue
public void StringBuilderExtensionEndsWith_OnCase_ReturnsTrue(string sbText, string test) {
// given
StringBuilder sb = new StringBuilder(sbText);
// when
bool result = sb.EndsWith(test);
// then
Assert.IsTrue(result);
}
示例4: StringBuilderExtensionEndsWith_ThrowsArgumentNullException_OnNullArg
public void StringBuilderExtensionEndsWith_ThrowsArgumentNullException_OnNullArg() {
// given
StringBuilder sb = new StringBuilder();
// when
ArgumentNullException exception =
Assert.Throws<ArgumentNullException>(() =>
sb.EndsWith(null));
// then
Assert.That(() => exception.ParamName, Is.EqualTo("text"));
}
示例5: GetEnumerator
/// <summary>
/// Returns an enumerator that iterates through the collection.
/// </summary>
/// <returns>
/// A <see cref="T:System.Collections.Generic.IEnumerator`1"/> that can be used to iterate through the collection.
/// </returns>
/// <filterpriority>1</filterpriority>
public IEnumerator<IPropertyBag> GetEnumerator()
{
// make sure this object is not disposed yet
CheckDisposed();
// create a buffer
var buffer = new StringBuilder();
// read until end of line or end of file
var inTextQualifier = false;
var firstLineRead = false;
var row = new PropertyBag();
var cellIndex = 0;
var headerList = new List<string>();
while (true)
{
// read the current character
var currentCharacter = input.Reader.Read();
// check for end of line
if (currentCharacter == -1)
yield break;
// append the character
buffer.Append((char) currentCharacter);
// check for text qualifier
if (buffer.EndsWith(format.TextQualifier))
{
// eat the text qualifier
buffer.Length -= format.TextQualifier.Length;
// toggle the flag
inTextQualifier = !inTextQualifier;
}
else if (inTextQualifier)
continue;
// check for column delimitor
if (buffer.EndsWith(format.ColumnDelimitor))
{
// eat the column delimitor
buffer.Length -= format.ColumnDelimitor.Length;
// get the read value
var value = buffer.ToString();
// if the first line is read, store the value in the row property bag
if (firstLineRead)
row.Set(headerList[cellIndex], value);
else
{
// if the first line contains the header, the value contains a column name, otherwise store the value in the row property bag
if (firstLineIsHeader)
headerList.Add(value);
else
{
// add a header to the list and store the value
headerList.Add(cellIndex.ToString(CultureInfo.InvariantCulture));
row.Set(headerList[cellIndex], value);
}
}
// reset the buffer
buffer.Length = 0;
// increment the cell index
cellIndex++;
// keep reading
continue;
}
// check for row delimitor
if (buffer.EndsWith(format.RowDelimitor))
{
// eat the row delimitor
buffer.Length -= format.RowDelimitor.Length;
// get the read value
var value = buffer.ToString();
buffer.Length = 0;
// set the value
if (!firstLineRead)
{
firstLineRead = true;
// if the first line contains the header, store the header value
if (firstLineIsHeader)
{
headerList.Add(value);
cellIndex = 0;
continue;
//.........这里部分代码省略.........
示例6: GetSccText
public static string GetSccText(string s, ref int errorCount)
{
int y = 0;
string[] parts = s.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
var sb = new StringBuilder();
bool first = true;
bool italicOn = false;
int k = 0;
while (k < parts.Length)
{
string part = parts[k];
if (part.Length == 4)
{
if (part != "94ae" && part != "9420" && part != "94ad" && part != "9426" && part != "946e" && part != "91ce" && part != "13ce" && part != "9425" && part != "9429")
{
// Spanish inverted question mark (extended char)
if (part == "91b3" && k < parts.Length - 1 && parts[k + 1] == "91b3")
{
sb.Append("¿");
k += 2;
continue;
}
// Spanish inverted exclamation mark (extended char)
if (part == "a180" && k < parts.Length - 2 && parts[k + 1] == "92a7" && parts[k + 2] == "92a7")
{
sb.Append("¡");
k += 3;
continue;
}
// skewed apos "’"
if (part == "9229" && k < parts.Length - 1 && parts[k + 1] == "9229" && sb.EndsWith('\''))
{
sb.Remove(sb.Length - 1, 1);
sb.Append("’");
k += 2;
continue;
}
if (part[0] == '9' || part[0] == '8')
{
if (k + 1 < parts.Length && parts[k + 1] == part)
k++;
}
var cp = GetColorAndPosition(part);
if (cp != null)
{
if (cp.Y > 0 && y >= 0 && cp.Y > y && !sb.ToString().EndsWith(Environment.NewLine) && !string.IsNullOrWhiteSpace(sb.ToString()))
sb.AppendLine();
if (cp.Y > 0)
y = cp.Y;
if ((cp.Style & FontStyle.Italic) == FontStyle.Italic && !italicOn)
{
sb.Append("<i>");
italicOn = true;
}
else if (cp.Style == FontStyle.Regular && italicOn)
{
sb.Append("</i>");
italicOn = false;
}
}
else
{
switch (part)
{
case "9440":
case "94e0":
if (!sb.ToString().EndsWith(Environment.NewLine))
sb.AppendLine();
break;
case "2c75":
case "2cf2":
case "2c6f":
case "2c6e":
case "2c6d":
case "2c6c":
case "2c6b":
case "2c6a":
case "2c69":
case "2c68":
case "2c67":
case "2c66":
case "2c65":
case "2c64":
case "2c63":
case "2c62":
case "2c61":
sb.Append(GetLetter(part.Substring(2, 2)));
break;
case "2c52":
case "2c94":
break;
default:
var result = GetLetter(part);
if (result == null)
{
sb.Append(GetLetter(part.Substring(0, 2)));
//.........这里部分代码省略.........
示例7: FixCasing
public void FixCasing(List<string> namesEtc, bool changeNameCases, bool makeUppercaseAfterBreak, bool checkLastLine, string lastLine)
{
var replaceIds = new List<string>();
var replaceNames = new List<string>();
var originalNames = new List<string>();
ReplaceNames1Remove(namesEtc, replaceIds, replaceNames, originalNames);
if (checkLastLine)
{
string s = HtmlUtil.RemoveHtmlTags(lastLine).TrimEnd().TrimEnd('\"').TrimEnd();
bool startWithUppercase = string.IsNullOrEmpty(s) ||
s.EndsWith('.') ||
s.EndsWith('!') ||
s.EndsWith('?') ||
s.EndsWith(". ♪", StringComparison.Ordinal) ||
s.EndsWith("! ♪", StringComparison.Ordinal) ||
s.EndsWith("? ♪", StringComparison.Ordinal) ||
s.EndsWith(']') ||
s.EndsWith(')') ||
s.EndsWith(':');
// start with uppercase after music symbol - but only if next line does not start with music symbol
if (!startWithUppercase && (s.EndsWith('♪') || s.EndsWith('♫')))
{
if (!Pre.Contains(new[] { '♪', '♫' }))
startWithUppercase = true;
}
if (startWithUppercase && StrippedText.Length > 0 && !Pre.Contains("..."))
{
StrippedText = char.ToUpper(StrippedText[0]) + StrippedText.Substring(1);
}
}
if (makeUppercaseAfterBreak && StrippedText.Contains(ExpectedCharsArray))
{
const string breakAfterChars = @".!?:;)]}([{";
const string expectedChars = "\"`´'()<>!?.- \r\n";
var sb = new StringBuilder();
bool lastWasBreak = false;
for (int i = 0; i < StrippedText.Length; i++)
{
var s = StrippedText[i];
if (lastWasBreak)
{
if (expectedChars.Contains(s))
{
sb.Append(s);
}
else if ((sb.EndsWith('<') || sb.ToString().EndsWith("</", StringComparison.Ordinal)) && i + 1 < StrippedText.Length && StrippedText[i + 1] == '>')
{ // tags
sb.Append(s);
}
else if (sb.EndsWith('<') && s == '/' && i + 2 < StrippedText.Length && StrippedText[i + 2] == '>')
{ // tags
sb.Append(s);
}
else if (sb.ToString().EndsWith("... ", StringComparison.Ordinal))
{
sb.Append(s);
lastWasBreak = false;
}
else
{
if (breakAfterChars.Contains(s))
{
sb.Append(s);
}
else
{
lastWasBreak = false;
sb.Append(char.ToUpper(s));
}
}
}
else
{
sb.Append(s);
if (breakAfterChars.Contains(s))
{
var idx = sb.ToString().IndexOf('[');
if (s == ']' && idx > 1)
{ // I [Motor roaring] love you!
string temp = sb.ToString(0, idx - 1).Trim();
if (temp.Length > 0 && !char.IsLower(temp[temp.Length - 1]))
lastWasBreak = true;
}
else
{
lastWasBreak = true;
}
}
}
}
StrippedText = sb.ToString();
}
ReplaceNames2Fix(replaceIds, changeNameCases ? replaceNames : originalNames);
}
示例8: LoadSubtitle
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
subtitle.Paragraphs.Clear();
subtitle.Header = null;
byte[] buffer = FileUtil.ReadAllBytesShared(fileName);
int i = 512;
Paragraph last = null;
while (i < buffer.Length - 25)
{
var p = new Paragraph();
int length = buffer[i + 1];
p.StartTime = DecodeTimestamp(buffer, i + 3);
if (last != null && last.EndTime.TotalMilliseconds == 0)
last.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds - 1;
if (length > 22)
{
int start = i + 7;
var sb = new StringBuilder();
int skipCount = 0;
bool italics = false;
//bool font = false;
for (int k = start; k < length + i; k++)
{
byte b = buffer[k];
if (skipCount > 0)
{
skipCount--;
}
else if (b < 0x1F)
{
byte b2 = buffer[k + 1];
skipCount = 1;
if (sb.Length > 0 && !sb.ToString().EndsWith(Environment.NewLine) && !sb.EndsWith('>'))
{
//if (font)
// sb.Append("</font>");
if (italics)
sb.Append("</i>");
sb.AppendLine();
//font = false;
italics = false;
}
//string code = VobSub.Helper.IntToBin(buffer[k] * 256 + buffer[k+1], 16);
//var codeBytes = new List<char>();
//if (b == 0x11 && b2 == 0x28)
//{
// sb.Append("<font color=\"red\">");
// font = true;
//}
//else
if (b == 0x11 && b2 == 0x2e)
{
sb.Append("<i>");
italics = true;
}
//foreach (char ch in code)
// codeBytes.Insert(0, ch);
//if (codeBytes[13] == '0' && codeBytes[14] == '0' && codeBytes[12] == '1' && codeBytes[6] == '1')
//{ // preamble address code
// if (code.Substring(11, 4) == "1000")
// {
// sb.Append("<font color=\"green\">");
// font = true;
// }
// else if (code.Substring(11, 4) == "0010")
// {
// sb.Append("<font color=\"blue\">");
// font = true;
// }
// else if (code.Substring(11, 4) == "0011")
// {
// sb.Append("<font color=\"cyan\">");
// font = true;
// }
// else if (code.Substring(11, 4) == "0100")
// {
// sb.Append("<font color=\"red\">");
// font = true;
// }
// else if (code.Substring(11, 4) == "0101")
// {
// sb.Append("<font color=\"yellow\">");
// font = true;
// }
// //else if (code.Substring(11, 4) == "0110")
// //{
// // sb.Append("<font color=\"magenta\">");
// // font = true;
// //}
//}
//else if (codeBytes[14] == '0' && codeBytes[13] == '0' && codeBytes[10] == '0' && codeBytes[9] == '0' && codeBytes[6] == '0' &&
// codeBytes[12] == '1' && codeBytes[8] == '1' && codeBytes[6] == '1')
//{ // midrow code
// if (code.Substring(11, 4) == "1000")
//.........这里部分代码省略.........
示例9: CalcWidthViaDraw
//.........这里部分代码省略.........
if (fontContent.Contains(" color="))
{
string[] arr = fontContent.Substring(fontContent.IndexOf(" color=", StringComparison.Ordinal) + 7).Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
if (arr.Length > 0)
{
string fontColor = arr[0].Trim('\'').Trim('"').Trim('\'');
try
{
colorStack.Push(c); // save old color
if (fontColor.StartsWith("rgb("))
{
arr = fontColor.Remove(0, 4).TrimEnd(')').Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
c = Color.FromArgb(int.Parse(arr[0]), int.Parse(arr[1]), int.Parse(arr[2]));
}
else
{
c = ColorTranslator.FromHtml(fontColor);
}
}
catch
{
c = parameter.SubtitleColor;
}
}
}
i += endIndex;
}
}
else if (text.Substring(i).StartsWith("</font>", StringComparison.OrdinalIgnoreCase))
{
if (text.Substring(i).ToLower().Replace("</font>", string.Empty).Length > 0)
{
if (lastText.EndsWith(' ') && !sb.StartsWith(' '))
{
string t = sb.ToString();
sb.Clear();
sb.Append(' ');
sb.Append(t);
}
float addLeft = 0;
int oldPathPointIndex = path.PointCount - 1;
if (oldPathPointIndex < 0)
{
oldPathPointIndex = 0;
}
if (sb.Length > 0)
{
if (lastText.Length > 0 && left > 2)
{
left -= 1.5f;
}
lastText.Append(sb);
TextDraw.DrawText(font, sf, path, sb, isItalic, parameter.SubtitleFontBold, false, left, top, ref newLine, leftMargin, ref newLinePathPoint);
}
if (path.PointCount > 0)
{
var list = (PointF[])path.PathPoints.Clone(); // avoid using very slow path.PathPoints indexer!!!
for (int k = oldPathPointIndex; k < list.Length; k++)
{
if (list[k].X > addLeft)
示例10: GenerateImageFromTextWithStyleInner
//.........这里部分代码省略.........
if (fontContent.Contains(" color="))
{
string[] arr = fontContent.Substring(fontContent.IndexOf(" color=", StringComparison.Ordinal) + 7).Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
if (arr.Length > 0)
{
string fontColor = arr[0].Trim('\'').Trim('"').Trim('\'');
try
{
colorStack.Push(c); // save old color
if (fontColor.StartsWith("rgb(", StringComparison.Ordinal))
{
arr = fontColor.Remove(0, 4).TrimEnd(')').Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
c = Color.FromArgb(int.Parse(arr[0]), int.Parse(arr[1]), int.Parse(arr[2]));
}
else
{
c = ColorTranslator.FromHtml(fontColor);
}
}
catch
{
c = parameter.SubtitleColor;
}
}
}
i += endIndex;
}
}
else if (text.Substring(i).StartsWith("</font>", StringComparison.OrdinalIgnoreCase))
{
if (text.Substring(i).ToLower().Replace("</font>", string.Empty).Length > 0)
{
if (lastText.EndsWith(' ') && !sb.StartsWith(' '))
{
string t = sb.ToString();
sb.Clear();
sb.Append(' ');
sb.Append(t);
}
float addLeft = 0;
int oldPathPointIndex = path.PointCount - 1;
if (oldPathPointIndex < 0)
{
oldPathPointIndex = 0;
}
if (sb.Length > 0)
{
if (lastText.Length > 0 && left > 2)
{
left -= 1.5f;
}
lastText.Append(sb);
TextDraw.DrawText(font, sf, path, sb, isItalic, parameter.SubtitleFontBold, false, left, top, ref newLine, leftMargin, ref newLinePathPoint);
}
if (path.PointCount > 0)
{
var list = (PointF[])path.PathPoints.Clone(); // avoid using very slow path.PathPoints indexer!!!
for (int k = oldPathPointIndex; k < list.Length; k++)
{
if (list[k].X > addLeft)
示例11: EndsWith_ContainsNonAsciiCharacters
public void EndsWith_ContainsNonAsciiCharacters()
{
StringBuilder builder = new StringBuilder();
builder.Append("\u3041\u3042\u3043\u3044");
string endString = "\u3043\u3044";
bool endsWith = builder.EndsWith(endString);
Assert.IsTrue(endsWith);
}
示例12: EndsWith_StringNotAtEnd
public void EndsWith_StringNotAtEnd()
{
StringBuilder builder = new StringBuilder();
builder.Append("abcdefg");
string endString = "bcd";
bool endsWith = builder.EndsWith(endString);
Assert.IsFalse(endsWith);
endString = "BCD";
endsWith = builder.EndsWith(endString, StringComparison.OrdinalIgnoreCase);
Assert.IsFalse(endsWith);
}
示例13: EndsWith_StringNull
public void EndsWith_StringNull()
{
StringBuilder builder = new StringBuilder();
builder.Append("abcdefg");
string endString = null;
bool endsWith = builder.EndsWith(endString);
}
示例14: EndsWith_StringEmpty
public void EndsWith_StringEmpty()
{
StringBuilder builder = new StringBuilder();
builder.Append("abcdefg");
string endString = string.Empty;
bool endsWith = builder.EndsWith(endString);
}
示例15: GenerateImageFromTextWithStyle
//.........这里部分代码省略.........
string fontContent = text.Substring(i, endIndex);
if (fontContent.Contains(" color="))
{
var arr = fontContent.Substring(fontContent.IndexOf(" color=", StringComparison.Ordinal) + 7).Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
if (arr.Length > 0)
{
string fontColor = arr[0].Trim('\'').Trim('"').Trim('\'');
try
{
colorStack.Push(c); // save old color
if (fontColor.StartsWith("rgb("))
{
arr = fontColor.Remove(0, 4).TrimEnd(')').Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
c = Color.FromArgb(int.Parse(arr[0]), int.Parse(arr[1]), int.Parse(arr[2]));
}
else
{
c = ColorTranslator.FromHtml(fontColor);
}
}
catch
{
c = _subtitleColor;
}
}
}
i += endIndex;
}
}
else if (text.Substring(i).StartsWith("</font>", StringComparison.OrdinalIgnoreCase))
{
if (text.Substring(i).ToLower().Replace("</font>", string.Empty).Length > 0)
{
if (lastText.EndsWith(' ') && !sb.StartsWith(' '))
{
string t = sb.ToString();
sb.Clear();
sb.Append(' ');
sb.Append(t);
}
float addLeft = 0;
int oldPathPointIndex = path.PointCount - 1;
if (oldPathPointIndex < 0)
oldPathPointIndex = 0;
if (sb.Length > 0)
{
TextDraw.DrawText(font, sf, path, sb, isItalic, subtitleFontBold, false, left, top, ref newLine, leftMargin, ref newLinePathPoint);
}
if (path.PointCount > 0)
{
PointF[] list = (PointF[])path.PathPoints.Clone(); // avoid using very slow path.PathPoints indexer!!!
for (int k = oldPathPointIndex; k < list.Length; k++)
{
if (list[k].X > addLeft)
addLeft = list[k].X;
}
}
if (addLeft == 0)
addLeft = left + 2;
left = addLeft;
if (_borderWidth > 0)
g.DrawPath(new Pen(_borderColor, _borderWidth), path);
g.FillPath(new SolidBrush(c), path);
path.Reset();