libs-base/Testing/string.m
netc c30836a60c Convert to the GNUstep makefile package.
The installation of the header files was modified slightly
to correspond with the GNUstep makefile package.  All OpenStep
headers go into Foundation while the gnustep-base specific
headers go into gnustep/base.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@2437 72102866-910b-0410-8b05-ffd578937521
1997-09-23 21:00:33 +00:00

63 lines
1.2 KiB
Objective-C

#include <Foundation/NSString.h>
/* For demo of Strings as Collections of char's. */
#include <Foundation/NSString.h>
void
print_string(NSString* s)
{
printf("The string [%s], length %d\n", [s cStringNoCopy], [s length]);
}
#include <Foundation/NSString.h>
int main()
{
id s = @"This is a test string";
id s2, s3;
print_string(s);
s2 = [s copy];
print_string(s2);
s3 = [s2 mutableCopy];
[s2 release];
s2 = [s3 copy];
[s3 release];
[s2 release];
s2 = [s copyWithZone: NSDefaultMallocZone ()];
print_string(s2);
s2 = [s stringByAppendingString:@" with something added"];
print_string(s2);
s2 = [s mutableCopy];
[s2 replaceCharactersInRange:((NSRange){10,4})
withString:@"changed"];
print_string(s2);
/* Test the use of the `%@' format directive. */
s2 = [NSString stringWithFormat: @"foo %@ bar",
@"test"];
print_string(s2);
#if 0
/* An example of treating a string like a Collection:
Increment each char. */
{
id s3;
void rot13(elt c)
{
[s3 appendElement:(char)(c.char_u + 1)];
}
s3 = [NSMutableString stringWithCapacity:[s2 length]];
[s2 withElementsCall:rot13];
print_string(s3);
}
#endif
exit(0);
}