如何在NSTextView中找到文本? [英] How to find the text in an NSTextView?

查看:153
本文介绍了如何在NSTextView中找到文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 NSTextView 中找到文本,并将其保存到文件。我可以做保存罚款。我已经使用了 -stringValue -textStorage 到目前为止,但都没有工作。当我把 -stringValue 插入时,它只是给我了(null),当我把 -textStorage 给我一个非常大的块没有什么(像长的一段不可见的文本)。

I need to find the text in an NSTextView, and save it to a file. I can do the saving fine. I have used -stringValue, and -textStorage so far, but neither have worked. When I put -stringValue in, it just gave me (null), and when I put -textStorage in, it gave me a very large chunk of nothing (like a long paragraph of invisible text).

如何从 NSTextView NSString

推荐答案

p>

Try

NSString *text = [[myTextView textStorage] string];

NSTextStorage继承自 NSMutableAttributedString ,继承自 NSAttributedString 。后者实现了 string 方法。

The NSTextStorage inherits from NSMutableAttributedString which inherits from NSAttributedString. The latter implements the string method.

这不是很明显,如果你只是看看NSTextView的实例方法在文档中。

This isn't too obvious if you just look at the NSTextView's instance methods in the documentation.

这篇关于如何在NSTextView中找到文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆