MendyK MendyK - 3 months ago 20
iOS Question

cant get 100,000+ hebrew characters into objective-c string

I have 100,000+ characters of text that need to be converted into a string so I can count the characters and display them on a page correctly, but in the text there are tons of quotations ("") and lots of commas, so it doesnt even turn into a string.
Does anyone know a way that you can ignore quotations and commas inside a NSString without having to do this \"" each time?

Here's some of the text. its english/hebrew

Psalm 30
...
Psalm 100
...

The following Psalm is not to be said on Shabbat, Festivals, the day before Pesach, Chol HaMoed Pesach, and the day of Yom Kippur
...

Answer

You say “I cant even turn the text into a string”. Since you said (in a comment) you're “just pulling it off this website”, the simplest way to do this is +[NSString stringWithContentsOfURL:encoding:error:]. This works for me:

    NSURL *url = [NSURL URLWithString:@"http://opensiddur.org/wp-content/uploads/2010/08/The-Blessing-Book-Nusa%E1%B8%A5-Ha-Ari-%E1%B8%A4aBaD-3.2.txt"];
    NSError *error;
    NSString *text = [NSString stringWithContentsOfURL:url usedEncoding:nil error:&error];
    NSLog(@"error=%@ text.length=%lu", error, (unsigned long)text.length);

You can look into NSURLSession or NSURLConnection when you want to do it in a non-blocking fashion.

If you plan to distribute the text in a file (named, let's say, “blessingBook.txt”) in your app bundle, you can get the URL this way:

    NSURL *url = [[NSBundle mainBundle] URLForResource:@"blessingBook" withExtension:@"txt"];

If you're loading it directly from your app bundle, you probably don't need to worry about using NSURLSession to load it in the background. You might want to do your “processing” in the background though, if it takes a while.