簡體   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