Copy a string: Difference between revisions

m
ab sort + lang tag
(→‎{{header|Tcl}}: added notes on value copying)
m (ab sort + lang tag)
Line 90:
dst[1] = 'a'; // Now src contains "Hallo"
 
=={{header|Objective-C}}==
 
Immutable strings - since they are immutable, you may get the same instance with its references count increased.
 
NSString *original = @"Literal String"
NSString *new = [original copy];
 
Mutable strings - you can get either new mutable or immutable string:
 
NSMutableString *original = @"Literal String"
NSString *immutable = [original copy];
NSMutableString *mutable = [original mutableCopy];
 
Copying a CString:
 
char *cstring = "I'm a plain C string";
NSString *string = [NSString stringWithUTF8String:cstring];
 
Copying from data, possibly not null terminated:
 
char bytes[] = "some data";
NSString *string = [[NSString alloc] initWithBytes:bytes length:9 encoding:NSASCIIStringEncoding];
 
And of course, if a C string is needed, you can use standard functions like strcpy.
 
=={{header|C++}}==
Line 329 ⟶ 305:
<lang modula3>VAR src: TEXT := "Foo";
VAR dst: TEXT := src;</lang>
 
=={{header|Objective-C}}==
 
Immutable strings - since they are immutable, you may get the same instance with its references count increased.
 
<lang objc> NSString *original = @"Literal String"
NSString *new = [original copy];</lang>
 
Mutable strings - you can get either new mutable or immutable string:
 
<lang objc> NSMutableString *original = @"Literal String"
NSString *immutable = [original copy];
NSMutableString *mutable = [original mutableCopy];</lang>
 
Copying a CString:
 
<lang objc> char *cstring = "I'm a plain C string";
NSString *string = [NSString stringWithUTF8String:cstring];</lang>
 
Copying from data, possibly not null terminated:
 
<lang objc> char bytes[] = "some data";
NSString *string = [[NSString alloc] initWithBytes:bytes length:9 encoding:NSASCIIStringEncoding];</lang>
 
And of course, if a C string is needed, you can use standard functions like strcpy.
 
=={{header|OCaml}}==