-
Notifications
You must be signed in to change notification settings - Fork 0
/
SasString.m
53 lines (38 loc) · 1.37 KB
/
SasString.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//
// SasString.m
// CronniX
//
// Created by Sven A. Schmidt on Sat Jan 04 2003.
// Copyright (c) 2003 Koch und Schmidt Systemtechnik GbR. All rights reserved.
//
#import "SasString.h"
@implementation NSString( SasString )
- (BOOL)startsWithNumber {
if ( [ self length ] < 1 ) return NO;
unichar firstChar;
[ self getCharacters: &firstChar range: NSMakeRange( 0, 1 ) ];
id numberSet = [ NSCharacterSet decimalDigitCharacterSet ];
return [ numberSet characterIsMember: firstChar ];
}
- (int)fieldCountSeperatedBy: (NSCharacterSet *)charSet {
NSScanner *scanner = [ NSScanner scannerWithString: self ];
NSString *dummy;
int fieldCount = 0;
while ( [ scanner scanUpToCharactersFromSet: charSet intoString: &dummy ] ) {
fieldCount++;
}
return fieldCount;
}
- (BOOL)startsWithStringIgnoringWhitespace: (NSString *)string {
id trimmedString = [ self stringByTrimmingCharactersInSet: [ NSCharacterSet whitespaceCharacterSet ]];
id pattern = [ NSString stringWithFormat: @"%@*", string ];
return [ trimmedString isLike: pattern ];
}
- (BOOL)startsWithString: (NSString *)string {
id pattern = [ NSString stringWithFormat: @"%@*", string ];
return [ self isLike: pattern ];
}
- (NSString *)stringByTrimmingWhitespaceAndNewline {
return [ self stringByTrimmingCharactersInSet: [ NSCharacterSet whitespaceAndNewlineCharacterSet ]];
}
@end