Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 从backword中搜索attributedString中的单词并获取范围Objective-C_Ios_Objective C_Uitextview_Nstextattachment - Fatal编程技术网

Ios 从backword中搜索attributedString中的单词并获取范围Objective-C

Ios 从backword中搜索attributedString中的单词并获取范围Objective-C,ios,objective-c,uitextview,nstextattachment,Ios,Objective C,Uitextview,Nstextattachment,如何从字符串末尾向后搜索attributedString中的空格“”(空格),然后获取该空格的范围 问题:正如你们所看到的,跳跃在两条线上,这是不正确的 我想要实现的逻辑是这样的,每当我得到新行时,我都会用\n替换空格,以便word从新行开始 每当我在键盘上按空格键时,我都会存储该空格的范围,当我得到换行符时,我会用空格替换 在伪代码中: int spaceIndex = -1 for i = 0 to string.length { if string.characters[stri

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

问题:正如你们所看到的,跳跃在两条线上,这是不正确的

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

每当我在键盘上按空格键时,我都会存储该空格的范围,当我得到换行符时,我会用空格替换

在伪代码中:

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
}

任何您需要实现的示例?此功能没有此类方法,您必须编写自己的逻辑来执行
string
NSString
)属性的
nsattributetstring
,并使用
NSString
方法:
rangeOfString:options:
?正如您看到的一样,单词在两行中,所以我想去获取最后一个空间范围,并替换为“\n”@SuryakantSharmaI。我认为向后搜索并没有真正的帮助。您的代码如何知道“跳跃”是拆分的?如果用户在“fox”之前插入一个单词会怎么样?断字最好在较低的(框架)级别处理,因为它取决于屏幕大小、字体大小、字符串长度等。