Code:
string testquestions = "1,2,100,3,4,101,98,99";
string[] qidarray = testquestions.Split(',');
StringBuilder sb = new StringBuilder();
foreach (string s in qidarray)
{
sb.Append(String.Format(@"({0}),",s));
}
string output= sb.ToString().Substring(0, sb.ToString().Length - 1);
Desired output =
(1),(2),(100),(3),(4),(101),(98),(99)
The code works. I want to know is this the best way for achieving the result. Is there a better way to achieve the desired result?
Is there a way not to use a foreach loop?