Skip to content

Instantly share code, notes, and snippets.

@peterkos
Created September 12, 2014 01:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterkos/e8f0853566e2f05a4940 to your computer and use it in GitHub Desktop.
Save peterkos/e8f0853566e2f05a4940 to your computer and use it in GitHub Desktop.
"Hello, World" by appending strings in a variety of languages. Just thought it would be fun to compare syntaxes.
//Objective-C
NSMutableString *str = [[NSMutableString alloc] initWithFormat:@"Hello "]; //NSMutableString *str = @"Hello,";
str = [str stringByAppendingString:@" world!"];
NSLog(@"%@", str); //Output: Hello, world!
//Java
String newString = "Hello, ";
String secondString = " world!";
newString += newString + oldString;
System.out.println(bothStrings); //Output: Hello, world!
//Swift
var str = "Hello,"
str += " world!"
println(str); //Output: Hello, World!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment