如何从 iPhone 中的 UITextView 获取空格(“”)后第一个键入的字母?

发布于 2024-12-28 10:35:50 字数 153 浏览 2 评论 0原文

我想从 UITextView 中输入的句子中获取最后一个单词。例如“Apple i”,在此示例中我需要获取“”(空格)之后的最后一个字母“i”。我想在用户在 UITextView 中输入时执行该功能。我如何从空白(“”)中获取用户之后的单词的第一个字母?有人可以帮忙解决这个问题吗?提前致谢。

I want to get the last word from the typed sentence in UITextView. For example "Apple i", from this example i need to get the last letter 'i' coming after " "(empty space). I want to do the functionality while the user typing in UITextView. How can i get the users first letter of the word after from empty space(" ")? Can anyone please help to solve this problem? Thanks in advance.

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

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

发布评论

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

评论(1

终弃我 2025-01-04 10:35:50

这是字符串逻辑。

return [[textView.text componentsSeparatedByString:@" "] lastObject];

您可以将此检查放入 UITextViewDelegate 方法 textView:shouldChangeTextInRange:replacementText: 中。不要忘记在此处返回YES。您还可以使用textViewDidChange:

Here is the string logic.

return [[textView.text componentsSeparatedByString:@" "] lastObject];

You can put this check in your UITextViewDelegate method textView:shouldChangeTextInRange:replacementText:. Don't forget to return YES here. You could also use textViewDidChange:.

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