Edit: missed the part about why there is no contains. IMHO it's because you can do contains, startswith, endswith etc against .ToString() which keeps StringBuilder focused on it's original intent to build efficient strings.
If we approach it from .ToString then we are dealing with a string.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Globalization.DateTimeFormatInfo;
namespace ConsoleNetCoreStringBuilder
{
class Program
{
public static List<string> MonthNames() =>
Enumerable.Range(1, 12).Select((index) => CurrentInfo.GetMonthName(index)).ToList();
static void Main(string[] args)
{
StringBuilder builder = new ();
MonthNames().ForEach(month => builder.AppendLine(month));
Console.WriteLine(builder.ToString().Contains("April")); // yes
Console.WriteLine(builder.ToString().Contains("april")); // no case sensitive
Console.WriteLine(builder.ToString().Contains("april", StringComparison.OrdinalIgnoreCase)); // yes ignore case
Console.ReadLine();
}
}
}
And then we can write an extension
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Globalization.DateTimeFormatInfo;
namespace ConsoleNetCoreStringBuilder
{
class Program
{
public static List<string> MonthNames() =>
Enumerable.Range(1, 12).Select((index) => CurrentInfo.GetMonthName(index)).ToList();
static void Main(string[] args)
{
StringBuilder builder = new ();
MonthNames().ForEach(month => builder.AppendLine(month));
Console.WriteLine(builder.Contains("April")); // yes
Console.ReadLine();
}
}
public static class Extensions
{
public static bool Contains(this StringBuilder sender, string text) =>
sender.ToString().Contains(text, StringComparison.OrdinalIgnoreCase);
}
}