gpt4 book ai didi

objective-c - 需要一些调查的 NSString

转载 作者:行者123 更新时间:2023-12-03 17:32:45 27 4
gpt4 key购买 nike

我有一个需要分析的文本文件。该文件包含一系列短句子,每个句子占一个新行。我通过使用 ComponentsSeparatedByString:@"\n"

构建一个行数组来完成此操作

这在大多数情况下都可以正常工作。如果我记录 @"This is the string ->%@<-That was the string"我得到

This is the string ->line1<-That was the string
This is the string ->line2<-That was the string
This is the string ->line3<-That was the string

但是对于某些行,我看到一个回车符:

This is the string ->line1<-That was the string
This is the string ->line2
<-That was the string
This is the string ->line3<-That was the string

我没有看到文件中的该行有任何不同,因此尝试将其复制并粘贴到 Word 中。我发现对于麻烦的部分,行在单词中是双倍行距的。其他部分我没有问题,但也没有。

这是怎么回事?是否有一些隐藏字符被拾取作为 NSString 的一部分?我该如何开始调查这个问题?

最佳答案

使用 hexdump 查看您的文件,看看是否有混合行结尾。您可能有一些以 \n 结尾的行,而其他行以 \r\n 结尾,这可能会造成困惑。一般来说,确保您的输入是干净的总是一个好主意!除此之外,您将需要扩展您的程序以处理任何导致困惑的情况。在调试器中查看字符串也会为您指明正确的方向。

关于objective-c - 需要一些调查的 NSString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4126468/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com