本文整理汇总了C#中System.Text.StringBuilder.Substring方法的典型用法代码示例。如果您正苦于以下问题:C# StringBuilder.Substring方法的具体用法?C# StringBuilder.Substring怎么用?C# StringBuilder.Substring使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Text.StringBuilder
的用法示例。
在下文中一共展示了StringBuilder.Substring方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main()
{
Console.Title = "StringBuilder substring test";
//Indexes 012345678901234
StringBuilder test = new StringBuilder("Test message!!!");
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write("The whole message -> ");
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine(test); // The whole message
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write("\nSubstring from index 5 with length 7 -> ");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine(test.Substring(5, 7)); // This will print message
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write("Substring from index 0 with length 4 -> ");
Console.ForegroundColor = ConsoleColor.Magenta;
Console.WriteLine(test.Substring(0, 4)); // Thisi will print Test
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write("Substring from index 5 without length -> ");
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(test.Substring(5)); // This will print message!!!
Console.WriteLine();
Console.ResetColor();
}
示例2: Main
static void Main(string[] args)
{
//test extension methods for StringBuilder
StringBuilder sb = new StringBuilder();
sb.Append("Once a type is defined and compiled into an assembly its definition is, more or less, final");
//add substring extension method, from index to the end
StringBuilder substringToEnd = sb.Substring(5);
Console.WriteLine(substringToEnd.ToString());
//the extension method from the exercise task
StringBuilder substring = sb.Substring(5, 6);
Console.WriteLine(substring.ToString());
//test IEnumerable extension methods
List<double> numbers = new List<double>();
numbers.Add(6.0);
numbers.Add(10.0);
numbers.Add(199.5);
numbers.Add(0.5);
numbers.Add(7.0);
numbers.Add(20.0);
double minElem = numbers.Min();
double maxElem = numbers.Max();
double sum = numbers.Sum();
double average = numbers.Average();
double product = numbers.Product();
Console.WriteLine("Min element: " + minElem + "\nMax element: " + maxElem);
Console.WriteLine("Sum : " + sum);
Console.WriteLine("Average : " + average);
Console.WriteLine("Product : " + product);
}
示例3: Main
static void Main()
{
StringBuilder sb = new StringBuilder();
StringBuilder test0 = sb.Substring(0, 0);
sb.Append("It's a spring out there!");
Console.WriteLine("Source string builder: {0}", sb);
Console.WriteLine();
StringBuilder sbPart = sb.Substring(7, 6);
Console.WriteLine("sb.Substring(7, 6) is processed.");
Console.WriteLine("Result string builder: {0}", sbPart);
Console.WriteLine();
sbPart = sb.Substring(0, 1);
Console.WriteLine("sb.Substring(0, 1) is processed.");
Console.WriteLine("Result string builder: {0}", sbPart);
Console.WriteLine();
sbPart = sb.Substring(0, sb.Length);
Console.WriteLine("sb.Substring(0, sb.Length) is processed.");
Console.WriteLine("Result string builder: {0}", sbPart);
Console.WriteLine();
sbPart = sb.Substring(1, sb.Length - 1);
Console.WriteLine("sb.Substring(1, sb.Length - 1) is processed.");
Console.WriteLine("Result string builder: {0}", sbPart);
Console.WriteLine();
}
示例4: Main
static void Main()
{
StringBuilder testExtension = new StringBuilder();
testExtension.Append("This tests the substring extension method");
Console.WriteLine(testExtension.Substring(15));
Console.WriteLine(testExtension.Substring(5,4));
}
示例5: Main
static void Main()
{
StringBuilder sb = new StringBuilder("abrakadabra");
Console.WriteLine(sb.Substring(4));
Console.WriteLine(sb.Substring(2,8));
}
示例6: Main
static void Main()
{
StringBuilder text = new StringBuilder();
text.Append("123456789");
Console.WriteLine(text.Substring(3, 3));
Console.WriteLine(text.Substring(3));
}
示例7: Main
static void Main()
{
StringBuilder test = new StringBuilder();
test.Append("This is the test for the substring extension!");
Console.WriteLine("Taking a substring from text with given index and length: " + test.Substring(12, 4));
Console.WriteLine("Taking a substring from text with given only index: " + test.Substring(12));
}
示例8: Main
static void Main()
{
StringBuilder sb = new StringBuilder();
sb.Append("some text goes here");
Console.WriteLine(sb.Substring(5, 4)); // "text"
Console.WriteLine(sb.Substring(10, sb.Length - 10)); // "goes here"
}
示例9: Main
internal static void Main()
{
var str = new StringBuilder();
str.Append("Hello my frind. Kefish sa na sun?");
str.Substring(5);
Console.WriteLine(str.Substring(3, 5).ToString());
Console.WriteLine(str.Substring(5).ToString());
}
示例10: Main
static void Main()
{
StringBuilder test = new StringBuilder("Hello Extension Methods");
StringBuilder result = test.Substring(1, 3);
Console.WriteLine(result);
result = test.Substring(2);
Console.WriteLine(result);
}
示例11: Main
static void Main(string[] args)
{
StringBuilder test = new StringBuilder("niso");
Console.WriteLine(test.Substring(0,2));
Console.WriteLine(test.Substring(2));
}
示例12: Main
static void Main()
{
StringBuilder a = new StringBuilder();
a.Append("Musaka s tarator");
Console.WriteLine(a.Substring(4));
Console.WriteLine(a.Substring(0, 3));
}
示例13: Main
public static void Main()
{
var test = new StringBuilder("Testing an extension method Substring for the class StringBuilder");
var firstTest = test.Substring(0, 37);
var secondTest = test.Substring(38);
Console.WriteLine(firstTest);
Console.WriteLine(secondTest);
}
示例14: Main
public static void Main()
{
StringBuilder input = new StringBuilder();
input.Append("Testing StringBuilder!");
StringBuilder result = input.Substring(8);
Console.WriteLine(result);
result = input.Substring(10, 3);
Console.WriteLine(result);
}
示例15: Main
public static void Main()
{
StringBuilder test = new StringBuilder();
test.Append("Hello, C#!");
Console.WriteLine("We are given string:{0}", test);
StringBuilder testResult = test.Substring(7);
Console.WriteLine("Substring starting from character at positon 7:"+testResult);
testResult = test.Substring(0, 5);
Console.WriteLine("Substring starting at position zero that has length 5 characters:"+testResult);
}