public void Insert() { using (var s = new NSMutableString(-1)) { s.SetString((NSString)"Hello World"); s.Insert((NSString)"!", s.Length); Assert.That(s.ToString(), Is.EqualTo("Hello World!"), "end"); Assert.Throws <ArgumentOutOfRangeException> (delegate { s.Insert((NSString)"@", -1); }, "negative"); Assert.Throws <ArgumentOutOfRangeException> (delegate { s.Insert((NSString)"oops", s.Length + 1); }, "out of range"); } }
public string ReplaceCharacters(string text, NSRange range, string newText) { if (text != null) { var strg = new NSString(text); var result = new NSMutableString(); result.Append(strg); var newContent = new NSString(newText); if (range.Length > 0) { result.Replace(range, newContent); return(text.Replace(text, newText)); } else { result.Insert(newContent, range.Location); return(result); } } return(string.Empty); }