Searching data from txt file in iOS

Ravi Ojha

I have a .txt file in which some data is present, when I stored it in an array I got 50000 words. I want to search the data from text file according to user input and show it on UITableview cell, how is it possible ? Can any body help me?

Here is my code to read data from .txt file in viewDidLoad:

NSString *filepath = [[NSBundle mainBundle] pathForResource:@"myList" ofType:@"txt"];
NSError *error;
NSString *fileContents = [NSString stringWithContentsOfFile:filepath encoding:NSUTF8StringEncoding error:&error];

if (error)
NSLog(@"Error reading file: %@", error.localizedDescription);

// maybe for debugging...
NSLog(@"contents: %@", fileContents);

NSArray *listArray = [fileContents componentsSeparatedByString:@"\n"];
NSLog(@"items = %d", [listArray count]);  
Ganesh Somani

You should use fast enumeration using block. Those are fastest of all for loop iteration. But changing the value in that array at time of enumeration could cause a crash.

Here is a link of how to use block enumeration

Here is a link of how it performance wise.

Hope this helps you!!

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

awk script to read data from txt file

分類Dev

Load rectangle data from txt file with Python?

分類Dev

How to write data to .txt file(FileWriter) from another class in javafx

分類Dev

Replace data at specific positions in txt file using data from another file

分類Dev

Reading variable from txt file

分類Dev

Downloading links from a txt file

分類Dev

Reading from a txt file in Java

分類Dev

Load Data Infile from txt

分類Dev

How to create a .txt file programmatically on iOS

分類Dev

Data not writing to the file in iOS

分類Dev

trying to plot histogram on realtime basis with set of data from a sensor using txt file

分類Dev

How do I load data from a txt file into variables in my C program?

分類Dev

How to run two function from same resource(plot graphic and saving infinite data to txt file)

分類Dev

searching(selecting) any data from LDAP server using JNDI

分類Dev

Remove data in txt file after 39 results

分類Dev

From tibble to txt or excel file in R

分類Dev

Login on java based from txt file

分類Dev

Extracting from excel (.xlsx) writing to .txt file

分類Dev

pulling a time stamp from a txt file

分類Dev

Read individual parts from HTML .txt file

分類Dev

Creating a dictionary in python from txt file

分類Dev

Reverse a String by reading from a txt file

分類Dev

Array/List from txt file in Python

分類Dev

Recursively Read from a .txt file Java

分類Dev

Particle Tracking by coordinates from txt file

分類Dev

Searching number in file

分類Dev

searching for file unix script

分類Dev

Searching a keyword in a pdf file

分類Dev

Searching for a sentence in a file java

Related 関連記事

ホットタグ

アーカイブ