在backword中搜索attributionString中的单词并获取范围Objective-C

时间:2016-03-29 11:30:47

标签: ios objective-c uitextview nstextattachment

如何从字符串末尾向后搜索一个attributesString中的空格“”(空格),然后获取该空格的范围?

问题:你可以看到跳跃是两行不正确。

我想要实现的逻辑是这样的,每当我得到新行时,我将用\ n替换空格,以便该字从新行开始。

每当我从键盘按空格按钮时,我正在存储该空间的范围,当我收到换行符时,我正在用空格替换\ n

enter image description here

1 个答案:

答案 0 :(得分:0)

在伪代码中:

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
}