In Apple documentation for NSString there is a stringByReplacingCharactersInRange method, however I cannot find this method in Monotouch.
Is this method implementation missing from Monotouch - native API binding?
I need this method to implement some custom string handling logic inside shouldChangeCharactersInRange
Here's some code to do what you need:
string text = field.Text;
string result;
result = text.Substring (0, range.Location) + replacement + text.Substring (range.Location + range.Length);
Not everything is binded for NSString
because it would mostly duplicate the .NET methods available in System.String
.
The easiest way is to work on .NET (native) string and create an NSString
from them if/when you need to interoperate with API that requires it. This has the advantages of minimizing the number of managed/unmanaged transitions (there's a small cost to that).
string s = "...";
var ns = new NSString (s);
Same goes if you receive a NSString
from the API, convert it into a string then manipulate it.
NSString ns = NSSomething.GetIt ();
string s = ns.ToString ();
If you find a specific binding that has no similar .NET method then please fill a bug report on http://bugzilla.xamarin.com and we'll make sure to include it in future releases of MonoTouch. Often an immediate workaround can be given to unblock you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With