NSString Flashcards

1
Q

stringByAppendingString Example

A

NSString *welcome = @”Welcome to “;
welcome = [welcome stringByAppendingString:@”the Flatiron School!”];

NSLog(@”%@”, welcome);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

string replacement example

A

NSString *shorthandWelcome = [welcome stringByReplacingOccurrencesOfString:stringToReplace withString:replacementString];

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

string prefix suffix check example

A

NSString *lafayette =
@”Marquis Marie-Joseph Paul Yves Roch Gilbert du Motier de Lafayette”;

BOOL isMarquis = [lafayette hasPrefix:@”Marquis”];
BOOL isLafayette = [lafayette hasSuffix:@”Lafayette”];

if (isMarquis && isLafayette) {
NSLog(@”Ladies and gentlemen, the Marquis de Lafayette”);
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

string check password example

A

NSString *password = @”p@ssw0rd”;
BOOL isValidPassword = [password isEqualToString:@”p@ssw0rd”];

if (isValidPassword) {
NSLog(@”Welcome to the Flatiron School!”);
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

NSString Convert to NSUInteger Example

A

NSString *ageString = @”29”;
NSUInteger age = [ageString integerValue];

age++; // birthday party!

NSLog(@”%lu”, age);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly