将 Unichar 数组转换为单个 NSString
我使用 NSString 对象中的“characterAtIndex:”创建了一个 unicode 字符数组。
我想将数组中的字符再次变成一个完整的字符串。
有什么方法可以将此 unicahr 数组转换为 NSStirng 吗? 有人可以帮我吗???
这是我的代码:
NSString *sentence = @"A long string";
NSString *new = [[NSString alloc]init];
unichar aBuffer[[sent length]];
int j=0;
//Tried to reverse the string:
for (int i=[sent length]-1; i>=0; i--,j++) {
aBuffer[j]=[sent characterAtIndex:i];
}
我找到了比这更好的逆转刺痛的方法,但请告诉我我们是否有任何方法可以做到这一点......
I created an unicode char array using 'characterAtIndex:' from an NSString object.
I want to make the characters in the array again into a single complete string.
Is there any method to convert this unicahr Array into NSStirng?
Can anyone please help me???
This s my code:
NSString *sentence = @"A long string";
NSString *new = [[NSString alloc]init];
unichar aBuffer[[sent length]];
int j=0;
//Tried to reverse the string:
for (int i=[sent length]-1; i>=0; i--,j++) {
aBuffer[j]=[sent characterAtIndex:i];
}
I found a better way for sting reversal than this, but let me know whether we have any method for this...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用免费桥接将 char 数组转换为 Objective-C 类或反向转换。
您可以使用数组创建一个 CFMutableStringRef 变量,假设该变量是 myString。您可以用它创建一个字符串或可变字符串。
You can use Toll-Free Bridging to turn a char array into an objective-c class or reverse.
You can create a
CFMutableStringRef
variable with your array lets say the variable is myString. Than you can create a string or a mutable string with it.您可以使用
getCharacters:range:
和stringWithCharacters:
与unichar
相互转换。You can convert to a
unichar
and back usinggetCharacters:range:
andstringWithCharacters:
.该数组是标准的 C 数组吗? (看起来像这样:
array[50];
)如果是,你可以这样做:Is the array a standard c array? (looks something like this:
array[50];
) If it is, you can do this:使用以下命令从字节数组中获取
NSString
:(您可以使用
UTF8String
而不是使用characterAtIndex:
循环遍历字符串)Get a
NSString
from a bytes array with:(and you could use
UTF8String
instead of looping through the string withcharacterAtIndex:
)