I tried the following implementation:
NSString *string = @" Test";
NSString *spaces = @"";
NSScanner *scanner = [NSScanner scannerWithString:string];
[scanner scanCharactersFromSet:[NSCharacterSet whitespaceCharacterSet] intoString:&spaces];
The number of whitespaces should be [spaces length]. However, all tests I tried always return 0.
Any ideas?
Use
setCharactersToBeSkipped:. The docs say,So it just silently skips the whitespace prefix.
There is another way to do it: