簡體   English   中英

從反向詞中搜索attributedString中的詞,並獲得范圍Objective-C

[英]Search word in attributedString from backword and get range Objective-C

如何從字符串末尾向后搜索attributedString中的空格“”(空格),然后獲取該空格的范圍?

問題:如您所見,跳線是兩行,這是不正確的。

我要實現的邏輯就是這樣,每當我得到新行時,我都會用\\ n替換空格,以便單詞從新行開始。

每當我從鍵盤上敲擊空格鍵時,我就會存儲該空格的范圍,當我換行時,我會用空格替換\\ n

在此處輸入圖片說明

用偽代碼:

int spaceIndex = -1

for i = 0 to string.length {
    if string.characters[string.length - i] == " " {
        spaceIndex = string.length - i
        break
    }
}
if spaceIndex != -1 {
// The space index found
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM