Different string-output with "umlaut"


#1

a question after running my version of the last example before the challenge.

in the return of nsstring *description in the class “employee” i’ve used an “umlaut” ( like in “Güter”)
:arrow_right: I wouldn’t use any “umlaut” nor other special characters inside the code for variablenames, objects, methods etc.

the output of the array then doesn’t show the “umlaut” itself, but probably kind of an Ascii-code ( \U00fc )
but surprise the following output of all the dellocating shows the ü itself.

why? I do guess something about the format specifiers? are there any rules and a solution to have the expected output? (maybe that’s googleable but here are the profs :wink: ) a link to a refering documentation?
explaining statements are very welcome, thank you.


#2
#import <Foundation/Foundation.h>

int main (int argc, const char * argv[])
{
    @autoreleasepool
    {
         NSString * (^umlaut)(bool) = ^ (bool uppercase) {
            return uppercase ? @"\U000000D6" : @"\U000000F6";
        };
        
        NSLog (@"---> umlaut: \U000000F6");
        NSLog (@"---> umlaut: \U000000D6");

        NSLog (@"---> umlaut: %@", umlaut (false));
        NSLog (@"---> umlaut: %@", umlaut (true));

    }
    return 0;
}

/*
2012-10-10 12:27:32.281 NSURL[36048:403] ---> umlaut: ö
2012-10-10 12:27:32.282 NSURL[36048:403] ---> umlaut: Ö
2012-10-10 12:27:32.282 NSURL[36048:403] ---> umlaut: ö
2012-10-10 12:27:32.282 NSURL[36048:403] ---> umlaut: Ö
*/

See UTF-8 encoding table and Unicode characters: utf8-chartable.de/


#3

thank you. I see.
it is quiet funny, it doesn’t matter if I

return [NSString stringWithFormat:@"<Arbeiter %d: $%3d in Gütern>", [self angestellterID], [self wertGueter]];

or

return [NSString stringWithFormat:@"<Arbeiter %d: $%3d in G\U000000fctern>", [self angestellterID], [self wertGueter]];

bothof them outputs

2012-10-10 22:48:04.850 BMI_Time[29385:403] Arbeiter: ( "<Arbeiter 0: $ 0 in G\U00fctern>", "<Arbeiter 1: $153 in G\U00fctern>", "<Arbeiter 2: $119 in G\U00fctern>", "<Arbeiter 3: $ 68 in G\U00fctern>", "<Arbeiter 4: $ 0 in G\U00fctern>", "<Arbeiter 5: $136 in G\U00fctern>", "<Arbeiter 6: $119 in G\U00fctern>", "<Arbeiter 7: $ 34 in G\U00fctern>", "<Arbeiter 8: $ 0 in G\U00fctern>", "<Arbeiter 9: $136 in G\U00fctern>" ) 2012-10-10 22:48:04.850 BMI_Time[29385:403] Gebe den Besitz eines Arbeiters auf 2012-10-10 22:48:04.851 BMI_Time[29385:403] deallocating <Arbeiter 5: $136 in Gütern>

:open_mouth: so, it seems: reading out the values of an whole array directly with %@ doesn’t allow(show) umlaut.
if it’s done with fast enumerating or somehow taken one by one it does.
see:

[code]#import <Foundation/Foundation.h>

int main (int argc, const char * argv[])
{
@autoreleasepool
{

    NSString *what = @"hühü";
    NSString *hu = @"hööööhü";
    NSLog (@"%@",what);
    NSLog (@"%@",hu);
    NSArray *that = [[NSArray alloc] initWithObjects:what, hu, nil];
    for (NSString *this in that) {
      NSLog(@"%@",this);
    }
  NSLog(@"%@", that);
}
return 0;

}
[/code]