Hi i have two string builders s1 and s2. I am assigning orders to that stringbuilder using comma separator. I want to compare two string builders. I want to know that all the orders in s1 are in s2 as well. If not i want know which order is missing in s2. How to achieve that?
if (!IsPostBack)
{
int reccount = dsResult.Tables[0].Rows.Count;
for (int count = 0; count < reccount;count++)
{
HashSet<string> arrayOrdId = new HashSet<string>();
arrayOrdId.Add(dsResult.Tables[0].Rows[count][1].ToString());
// arrayOrdId[count] = dsResult.Tables[0].Rows[count][1].ToString();
}
}
I would suggest not using
StringBuilderat all for this – instead, create twoList<string>or possiblyHashSet<string>to build up the order IDs, then compare those. If you need to create a string representation for other reasons, do that separately. (I’m assuming your order IDs are strings. If they’re not, use the appropriate type of collection instead.)It’s not clear whether the order matters, but if it doesn’t,
HashSet<string>is what you should be using. You can find the differences easily enough: