我是 iphone 开发的菜鸟,我对 xcode 有一个非常奇怪的问题。出于某种原因,它会在我的字符串末尾随机添加尾随空格。我的初始字符串值是从 xml 解析的,然后我尝试从那里获取字符串的最后一部分。由于这个随机的空白,这被证明是困难的。任何帮助是极大的赞赏。
我的代码
//initial String
<title>March 15 2013 Metals Commentary: Thomas Vitiello</title>
//Parsing
NSString *name = [[stories objectAtIndex: storyIndex] objectForKey: @"title"];
NSLog(@"myname: %@ %i", name, name.length);
//Log at this point
myname: March 15 PM Metals Commentary: Thomas Vitiello
59
//Attempt at Removing Whitespace
NSArray *lastName=[name componentsSeparatedByString:@" "];
name = [[lastName objectAtIndex:6]stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSLog(@"myname: %@ %i", name, name.length);
//Log at this point
myname: Vitiello
9 //<--Should be 8, not 9. This annoying whitespace is also particularly long, taking more than 1 character space, despite obviously being 1 character long.