I have to iterate data through some DIV's. I don't know how to share and debug the code with others, so I decided to put the code in C# in a console application if you don't mind.
Problem is that I cannot close section div in this iteration. If you have a better idea, please, share. I'm stuck.
Thank you.
string[] someWords = { "auto", "botox", "amater", "test_phase", "warengruppen", "axel" };
List<char> letters = new List<char>();
Array.Sort(someWords);
someWords.ToList();
//fill b list with alphabet
foreach (var characters in someWords) {
if (!letters.Contains(characters[0])) {
letters.Add(characters[0]);
}
}
letters.Sort();//make it asc
int i = 0;
string substitute = "";
string output = "";
output += "\n<div class='wrap'>";
while (i < someWords.Count()) {
foreach (var c in letters) {
if (someWords[i].StartsWith(Convert.ToString(c))) {
if (substitute != Convert.ToString(c)) {
substitute = Convert.ToString(c);
output += "\n<div class='section_" + substitute + "'>";
}
output += "\n<div class='container'>";
output += "\n" + someWords[i];
output += "\n</div>";//end of container div
substitute = Convert.ToString(c);
}
output += "\n</div>"; //end of section div
}
i++;
}
output += "\n</div>";//end of wrap div
Console.WriteLine(output);
The result I would like to have:
<div class='wrap'>
<div class='section_a'>
<div class='container'>
amater
</div>
<div class='container'>
auto
</div>
<div class='container'>
axel
</div>
</div> //end of section_a
<div class='section_b'>
<div class='container'>
botox
</div>
</div> //end of section_b
<div class='section_t'>
<div class='container'>
test_phase
</div>
</div> //end of section_t
<div class='section_w'>
<div class='container'>
warengruppen
</div>
</div> //end of section_w
</div> //end of wrap div