gpt4 book ai didi

ios - 如何转换数组的字符串值

转载 作者:行者123 更新时间:2023-12-01 17:28:53 24 4
gpt4 key购买 nike

我有保存以下值的数组:

globalarray_beacon: (
"(01000466)",
"(01000008)",
"(01000003)",
"(01000001)",
"(01000006)",
"(01000004)",
"(01000007)",
"(01000005)",
"(01000469)",
"(01000468)",
"(01000420)",
"(01000002)",
"(01000444)",
"(01000463)",
"(01000468)",
"(01000466)",
"(01000001)",
)

我想将此值转换为以下内容:
globalarray_beacon: ( 
01000468,
01000004,
01000006,
01000420,
01000444,
01000466,
01000469,
01000003,
01000005,
01000008,
01000001,
01000007,
01000002
)

尝试1。
NSArray *items = [theString componentsSeparatedByString:@" " "];

尝试2。
 NSString *stringWithoutSpaces = [myString 
stringByReplacingOccurrencesOfString:@"()" withString:@""];

试试3。
  for (int i=0; i<array_lastname.count; i++) {


[array_data addObject:[[array_lastname objectAtIndex:i] componentsSeparatedByString:@"()"]];

}

如何转换数组的值我不得不尝试很多事情。如何将字符串值转换为数据。
提前致谢。

最佳答案

NSString有一个便捷的方法stringByTrimmingCharactersInSet可以做到这一点

NSArray *globalarray_beacon = @[@"(01000466)", @"(01000008)", @"(01000003)", @"(01000001)", @"(01000006)", @"(01000004)", @"(01000007)", @"(01000005)", @"(01000469)", @"(01000468)", @"(01000420)", @"(01000002)", @"(01000444)", @"(01000463)", @"(01000468)", @"(01000466)", @"(01000001)"];
NSMutableArray *trimmedArray = [NSMutableArray array];
for (NSString * string in globalarray_beacon) {
[trimmedArray addObject:[string stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"()"]]];
}
NSLog(@"%@", trimmedArray);

关于ios - 如何转换数组的字符串值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41952817/

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