// 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 = Math.Min(maxlen, s.Length); bool intag = false; for(int i = 0; i < res; i++) { switch(s[i]) { case '<': intag = true; break; case '>': intag = false; break; default: // nothing break; } } 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)) + "|"); } } } }