是否有“stringByReplacingCharactersInRange” Monotouch中NSString的方法?

发布于 2024-12-13 09:30:52 字数 404 浏览 3 评论 0原文

在 Apple 文档中 NSString< /a> 有一个 stringByReplacingCharactersInRange 方法,但是我在 Monotouch 中找不到这个方法。

Monotouch - 本机 API 绑定中是否缺少此方法实现?

我需要这个方法来实现 shouldChangeCharactersInRange 内的一些自定义字符串处理逻辑

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦幻的味道 2024-12-20 09:30:52

这里有一些代码可以完成您需要的操作:

string text = field.Text;
string result;

result = text.Substring (0, range.Location) + replacement + text.Substring (range.Location + range.Length);

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);
余生共白头 2024-12-20 09:30:52

并非所有内容都绑定到 NSString,因为它大部分会复制 System.String 中可用的 .NET 方法。

最简单的方法是处理 .NET(本机)字符串,并在您需要与需要它的 API 进行互操作时从中创建一个 NSString。这样做的优点是最大限度地减少托管/非托管转换的数量(成本很小)。

string s = "...";
var ns = new NSString (s);

如果您从 API 收到 NSString,将其转换为字符串然后对其进行操作,情况也是如此。

NSString ns = NSSomething.GetIt ();
string s = ns.ToString ();

如果您发现没有类似 .NET 方法的特定绑定,请在 http://bugzilla.xamarin.com 上填写错误报告 我们将确保将其包含在 MonoTouch 的未来版本中。通常可以立即提供解决方法来解锁您。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文