繁体   English   中英

如何从NSTextView的段落开头删除字符?

[英]How do I delete characters from the beginning of a paragraph in a NSTextView?

我正在将列表/项目符号添加到NSTextView,现在,当用户选择“切换项目符号”按钮时,我正在将项目符号段落改回普通段落。 为了做到这一点,我想出了如何检查段落是否为项目符号样式并更改其余样式的方法,但是我需要能够从列表中删除前三个字符(带有项目符号标志符号)。段。 理想情况下,我将插入光标放在该段的末尾。 有人可以帮忙吗?

在您的类文件中,您将有一个NSString(带有项目符号的段落),然后将NSString放入了textview中,对吗?

要取出所有项目符号符号文本,只需执行以下操作:

NSString *paragraphsWithBullets = @"(bullet) paragraph";

if ([paragraphsWithBullets rangeOfString:@"bullet"].location == NSNotFound) {

// string doesn't contain bullets
textview.text = paragraphsWithBullets;

} else {

// string does contain bullets
NSString *paragraphWithoutBullets = [paragraphsWithBullets stringByReplacingOccurrencesOfString:@"bullet" withString:@""];

textview.text = paragraphWithoutBullets;

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM