Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS: Display NSArray of NSStrings in a label with special character encoding
    primarykey
    data
    text
    <p>I have several <code>NSStrings</code> which I add to an <code>NSArray</code>. The string may contain special characters. In the end I want to print the array to a <code>UILabel</code>.</p> <p>The very simplified code (if you think I missed something, let me know):</p> <pre><code>NSString *strBuffer = @"Röckdöts"; NSLog(@"String: %@", strBuffer); NSMutableArray *marrSelectedStrings = [[NSMutableArray alloc] init]; [marrSelectedStrings addObject:strBuffer]; NSLog(@"Array: %@", marrSelectedStrings); NSUInteger iCount = [marrSelectedStrings count] for (NSUInteger i = 0; i &lt; iCount; i++) { NSLog(@"element %d: %@", i, [marrSelectedStrings objectAtIndex: i]); } </code></pre> <p>In a different <code>UIViewController</code>:</p> <pre><code>self.label.text = [NSString stringWithFormat:@"%@", marrSelectedStrings]; </code></pre> <p>The string itself prints out fine. For the array however, it depends on the output method, whether the console diplays the correct special character or code for it. The label only prints code instead of the real characters. The print out via <code>NSLog</code> looks like the following:</p> <pre><code>Buffer: Röckdöts Array: ( R\U00f6ckd\U00f6ts ) element 0: Röckdöts </code></pre> <p>Whereas the label reads:</p> <blockquote> <p>R\U00f6ckd\U00f6ts</p> </blockquote> <p>I tried using <code>stringWithUTF8String</code> during the adding to the array as well as encoding during assigning it to the label like so, but it didn't change the result:</p> <pre><code>// adding with UTF8 encoding [marrSelectedStrings addObject:[NSString stringWithUTF8String:[strBuffer UTF8String]]]; // printing to label with UTF8 encoding self.label.text = [NSString stringWithUTF8String:[[NSString stringWithFormat:@"%@", marrSelectedStrings] UTF8String]]; </code></pre> <p>Is there an easier way to simply print the array with correct character encoding to the <code>UILabel</code> than iterating over the array and appending every single word?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload