public static string trimEnd(string self) { int len = self.Length; if (len == 0) return self; int pos = len-1; if (self[pos] > ' ') return self; while (pos >= 0 && self[pos] <= ' ') pos--; return self.Substring(0, pos+1); }