Split NSArray based on characters


            

Arrays are omnipresent. As I needed a snippet to make a string into an array of values, I thought would be helpful to share this for beginners.

For example, take a string variable like,

NSString *str = [[NSString alloc] initWithFormat:@"This##is##string##conversion##example"];

Create an array variable “array1” as:-

NSArray *array1 = [[NSArray alloc] initWithArray:[str componentsSeparatedByString:@"##"]];
for (int i=0;i<array1.count; i++) {
   NSLog(@"place name at index %d: %@\n", i, [array1 objectAtIndex:i]);
}

I used the for loop to know the array1 values, which is displayed in Console output:

2013-10-17 01:26:12.335 PickerViewTest[21740:a0b] place name at index 0: This
2013-10-17 01:26:12.337 PickerViewTest[21740:a0b] place name at index 1: is
2013-10-17 01:26:12.337 PickerViewTest[21740:a0b] place name at index 2: string
2013-10-17 01:26:12.338 PickerViewTest[21740:a0b] place name at index 3: conversion
2013-10-17 01:26:12.338 PickerViewTest[21740:a0b] place name at index 4: example

Hope it helps.

Bootable USB Drive with OS X Mavericks — Fastest Way

Apple released its latest OS X version, 10.9 or “Mavericks”. Quote Apple: “With more than 200 new features, OS X Mavericks brings Maps and iBooks to the Mac, introduces Finder Tabs and Tags, enhances multi-display support and includes an all-new version of Safari.” Cool, ain’t it ? But this I like most: “The latest release […]

iOS 7 UIPickerView Simple Application

Recently I was asked by a friend to provide some support with UIPickerView in iOS 7. He was a bit puzzled by what it seemed to be the impossibility to pad the content of each picker view row to a certain distance from the left side of the UIPickerView. Basically, let’s consider the following example. […]

Simple and default UIPickerView

Leave a Reply

Your email address will not be published. Required fields are marked *