I am trying to write a bit of code to take a string (this string automatically changes based on the day of the week), parse this string into chars, and retrieve the chars in order at certain points. Here’s how it would need to be used:
if (DateIsBetween(aPeriodMWF, legitDate, bPeriodMWF)) period=aPeriod;
if (DateIsBetween(bPeriodMWF, legitDate, cPeriodMWF)) period=bPeriod;
if (DateIsBetween(cPeriodMWF, legitDate, dPeriodMWF)) period=cPeriod;
if (DateIsBetween(dPeriodMWF, legitDate, ePeriodMWF)) period=dPeriod;
if (DateIsBetween(ePeriodMWF, legitDate, fPeriodMWF)) period=ePeriod;
if (DateIsBetween(fPeriodMWF, legitDate, gPeriodMWF)) period=fPeriod;
if (DateIsBetween(gPeriodMWF, legitDate, aPeriodMWF)) period=gPeriod;
if (period==1) {
if(parsedCharacter='A') nextPeriodLabel.text="A Period Class";
//repeat for parsedCharacter = b,c,d,e,f,g
}
if (period==2) {
//Do the same thing, but get the second character in the string
}
In this code, “parsedCharacter” needs to reflect the first character in the sequence. In the next statement however, it will have to reflect the next character in the string.
Here is the code for getting the strings:
if (currentWeekType == 1) {
if ([weekDay isEqualToString:@"Wednesday"]) sequenceString = @"ABCDEF";
if ([weekDay isEqualToString:@"Friday"]) sequenceString = @"DGCFEAB";
}
To retrieve the individual characters you could use
[myString characterAtIndex:i]whereiis the index within the string. Depending on your need you could either hardcode the index numbers or use a counter variable to increment it (and thus getting the next character). Of course you could also copy your NSString into an NSMutableString and remove the first character after extracting a character but this is probably a lot slower than using an index variable. Beware of running over the end of the string though (larger index than string size).