ObjC is so hard to read!!! Meanwhile…
@paul I used a similar example in a talk on how Cobol works. I said something like "Oh, you think Cobol is wordy, huh? Then what do you say about this code in a modern language calling a modern API?" Although come to think of it, my example might have actually been in ObjC…
@waltman syntax is always clearer on the other side.

@paul Here's the example I used:

NSString *yourString = [whitespaceString stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceCharacterSet]];

NSString *yourString = [whitespaceString stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];

I originally did this talk for a Perl conference. As you can imagine, the equivalent code is a LOT shorter in Perl. 😀

@waltman why twice or was it just examples of trimming differently.

@paul Are `whitespaceCharacterSet` and `whitespaceAndNewlineCharacterSet` two different constants in the API? I'm sure I just copied that from the API docs but I don't remember. In any event, in Perl you'd either use `chomp` or a very simple regex if you wanted finer control. That second command would be something like

$yourString =~ s/\s+$//;

in Perl.

@waltman the newline one is a superset of the whitespace one, so you only need to trim that. And while yeah that particular API is a bit long winded it's just a method that takes a single argument and returns something.
@paul @waltman Not if you want to retain the newline. (I’m assuming these are supposed to be two different examples)

@pdcawley @paul I thought the second example was supposed to trim the newline, so that's why I went with that example. My intention wasn't to give every possibility but just demonstrate what the equivalent Perl code might look like. It's easy enough to use a character class in your regex to remove anything you want.

That said, I'm having a hard time thinking of a case where I wanted to trim trailing whitespace and *not* also trim the newlines. Maybe it comes up more often in GUI programming than CLI tools?