---
title: "How to get First Character from each string of an Array"  
description: "How to get First Character from each string of an Array"  
author: "zack mathews"  
published: 2015-11-18  
updated: 2015-11-18  
canonical: https://www.mindstick.com/forum/33604/how-to-get-first-character-from-each-string-of-an-array  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 1 minute  

---

# How to get First Character from each string of an Array

I have an [Array](https://www.mindstick.com/articles/335/jagged-array-in-c-sharp-dot-net) of [String](https://www.mindstick.com/articles/1527/string-split-in-c-sharp), I would like to know how to [fetch](https://www.mindstick.com/forum/156159/what-is-google-fetch) the first [character](https://www.mindstick.com/articles/23551/an-investigate-distinctive-seafood-restaurant-for-your-image-stamp-character) of each string when the first character is different to [previous](https://yourviews.mindstick.com/view/81421/unlock-2-0-is-just-like-previous-corona-lockdowns) strings.\
For example:\
NSArray *arr = @[@"AA", @"AAA", @"B", @"BBB", @"BBBB", @"CC", @"DD"];\
I want these character in another array:\
A,B,C,D\
Please help me.\
\

## Replies

### Reply by Tarun Kumar

For fetching and storing first character in an array use code like this:

```
NSArray *stringArray = @[@"AA", @"AAA", @"B", @"BBB", @"BBBB", @"CC", @"DD"];NSMutableArray *fetchedArray = [NSMutableArray stringArray];NSMutableSet *mutableSet = [[NSMutableSet alloc]init];for (NSString *str in stringArray){    if(![mutableSet containsObject:[str substringToIndex:1]])        [fetchedArray addObject:[str substringToIndex:1]];    [mutableSet addObject:[str substringToIndex:1]];}NSLog(@"%@", fetchedArray);
```

I hope the above code is helpful for you.


---

Original Source: https://www.mindstick.com/forum/33604/how-to-get-first-character-from-each-string-of-an-array

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
