Best way to search .rtf file for value?

Hi all, I'm new to the community and i'm eagar to learn swift.

I'm starting out with a simple application.. However I have come across a small hurdle.


What is the best way to search an internal .rtf file for a value? The purpose of my applicable is to search a local rtf file for a zip/post code to see if it exists. The values in the file are one per line. If the value exists i'll create i'll create a "OK" alert, if not, i'll show an alternative alert.


Thanks in advance for taking the time to read and help me.


Neil

Have a look here to see how to get the text in a textView ; you could also just put in in a temporary or just make the outlet hidden :


http : / / stackoverflow.com/questions/29679229/how-to-upload-rtf-file-in-ui-text-view-in-swift-code


import UIKit
import Foundation

class ViewController: UIViewController {
     var fullText = "" as NSString
    @IBOutlet var textView: UITextView!
    override func viewDidLoad() {
        super.viewDidLoad()
        if let rtf = NSBundle.mainBundle().URLForResource("rtfdoc", withExtension: "rtf", subdirectory: nil, localization: nil) {
        do {
         let attrString = try NSMutableAttributedString(URL: rtfPath, options: [NSDocumentTypeDocumentAttribute:NSRTFTextDocumentType], documentAttributes: nil)
                textView.attributedText = attrString
          // or
     fullText = attrString.string as NSString     // that will ease search
       } catch{}

        }
    }
}

Once you have the text, you can search for the substring in it:


        let startingSequence = theZipCode       
        let startRange = fullText.rangeOfString(startingSequence) 
        if startRange.length > 0 {
          // create a "OK" alert

     } else {
          show an alternative alert

}



Thanks to tell if that works.

Best way to search .rtf file for value?
 
 
Q