// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; namespace E { public class Program { public static int IndexOfNonTag(string s, int maxlen) { int res = 0; bool intag = false; int n = 0; while(res < s.Length && n < maxlen) { switch(s[res]) { case '<': intag = true; break; case '>': intag = false; break; default: if(!intag) n++; break; } res++; } if(!intag) { return res; } else { while(res >= 0 && s[res] != '<') res--; return res; } } public static void Main(string[] args) { string s = "txt txt longtxt longtxt "; for(int i = 10; i < s.Length; i++) { Console.WriteLine(i + ": |" + s.Substring(0, IndexOfNonTag(s, i)) + "|"); } } } }