// 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 string GoodCut(string s, int maxlen) { int res = 0; bool intag = false; while(res < s.Length && res < maxlen) { switch(s[res]) { case '<': intag = true; break; case '>': intag = false; break; default: break; } res++; } if(intag) { while(res >= 0 && s[res] != '<') res--; } return s.Substring(0, res); } public static void Main(string[] args) { string s = "txt txt longtxt longtxt "; for(int i = 10; i < s.Length; i++) { Console.WriteLine(i + ": |" + GoodCut(s, i) + "|"); } } } }