Paul,
>>>>>> Paul Lynch (PL) wrote at Tue, 20 Nov 2001 16:04:31 +0000:
PL> public String bidify(String value) {
PL> NSArray tmpArray = NSArray.componentsSeparatedByString(value,
PL> "\n\n");
PL> String tmpStr = tmpArray.componentsJoinedByString("<fred>");
PL> tmpArray = NSArray.componentsSeparatedByString(tmpStr, "\n");
PL> tmpStr = tmpArray.componentsJoinedByString(" ");
PL> tmpArray = NSArray.componentsSeparatedByString(tmpStr, "<fred>");
PL> tmpStr = tmpArray.componentsJoinedByString("\n");
PL> return tmpStr;
PL> }
Where's the code for reading source / writing result? ;)
PL> Shame about fred. An Objective C version would be simpler, of
PL> course :-).
It would -- here it is:
void main() {
int cc,prev=0;
while ((cc=getchar())!=EOF) {
putchar(cc!='\n'?cc:prev=='\n'?'\n':' ');
prev=cc;
}
#if WANT_LAST_EOL
if (prev=='\n') putchar('\n');
#endif
}
(Yeah, it's a proper ObjC -- no reason to use Foundation for tasks like this
one ;)))
If you really wanted NSStrings, well, one (not quite the best) possibility might be
NSString *rewrap(NSString *s) {
NSMutableArray *ma=[NSMutableArray array];
NSEnumerator *en=[[s componentsSeparatedByString:@"\n\n"] objectEnumerator];
while (s=[en nextObject])
[ma addObject:[[s componentsSeparatedByString:@"\n"]
componentsJoinedByString:@" "]];
return [ma componentsJoinedByString:@"\n"];
}
It's short and intelligible, but not quite effective nor quite proper (odd
numbers of \n's won't be interpreted correctly).
---
Ondra Cada
OCSoftware: [log in to unmask] http://www.ocs.cz
2K Development: [log in to unmask] http://www.2kdevelopment.cz
private [log in to unmask] http://www.ocs.cz/oc
|