If you really want to stick with a StringBuilder you can use an extension method to give you a List and then you can access it with an element number.
internal static class ExtensionMethods
{
public static List<string> ToList(this StringBuilder stringBuilder)
{
return stringBuilder.ToString().Split(new string[] { Environment.NewLine }, StringSplitOptions.None).ToList();
}
}
You can then access it by calling the ToList() method.
int i = 0;
StringBuilder SB = new StringBuilder();
while (i++ != 1000000)
{
SB.AppendLine(i.ToString());
}
string ChosenElement = SB.ToList()[1000];
StringBuilder
is the wrong object that you should be using, what are you trying to do? – OperationStringBuilder
", causing you to have the problem Y: "But now I can't get separate strings back from theStringBuilder
". Explain your original problem X. – NumismatistAppend
with a separator<space>
(may be). and split withSplit(separator)
and showelements[0]
where elements is the array of splits. – Vicara possibility
. Glad to see you have another. – VicarList<>
option but may be OP would like to stick withStringBuilder
for no reason. One has the right to provide alternatives which may/may not be buggy for others. – Vicar