获取连续模式的最后一行

时间:2016-02-17 06:22:12

标签: tcl

我在一行中有一个模式,如果文件中连续出现,我想得到最后一行。

示例文件:

IPad

预期产出:

import UIKit

class ViewController: UIViewController,UIImagePickerControllerDelegate,UINavigationControllerDelegate,UIPopoverPresentationControllerDelegate {
    var imagePicker = UIImagePickerController()
    var popController:UIPopoverPresentationController!
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


    @IBAction func btn_action(sender: UIButton) {
        if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.SavedPhotosAlbum) {

            self.imagePicker.delegate = self
            self.imagePicker.sourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum
            self.imagePicker.allowsEditing = true
            imagePicker.modalPresentationStyle = UIModalPresentationStyle.Popover
            self.presentViewController(self.imagePicker, animated: true, completion: nil)
            popController = imagePicker.popoverPresentationController!
            popController.permittedArrowDirections = UIPopoverArrowDirection.Up
            popController.delegate = self
            popController.sourceView = self.view
            let contentSize : CGSize = CGSizeMake(500,400)
            self.imagePicker.preferredContentSize = contentSize
            popController.backgroundColor=UIColor.redColor()
            popController.sourceRect = CGRectMake(sender.frame.origin.x + sender.bounds.width/2-5, sender.frame.origin.y+sender.bounds.size.height/2, 10, 10)
        }
    }

    internal override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask
    {
        return UIInterfaceOrientationMask.Landscape
    }
    func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject])
    {

    }
    func imagePickerControllerDidCancel(picker: UIImagePickerController)
    {
        imagePicker.dismissViewControllerAnimated(true, completion: nil)
    }
}

extension UIImagePickerController
{
    public override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask
    {
        return UIInterfaceOrientationMask.Landscape
    }
}

1 个答案:

答案 0 :(得分:1)

假设每一行都是一个正确的列表,那就是记住最后一行并在与当前值不同时打印前一个值。

gets $fin oldline;        # Assume there's at least one line for simplicity of coding
while {[gets $fin newline] >= 0} {
    if {[lindex $newline 0] ne [lindex $oldline 0]} {
        puts $oldline;    # There was a difference, so print out the old one
    }
    set oldline $newline; # Save the new line we read for the next iteration
}
puts $oldline;            # The last line to be read hasn't been printed yet

确定两条线是否相同是主要问题;与仅仅应用lindex相比,实际数据可能更复杂。这是您使用regexpscan来解析数据的地方,以及如何执行此操作是一个非常重要的问题,需要实际了解实际数据的格式。

处理完全没有线路的情况是一个单独的问题。通过检查初始gets的返回值,如果它小于零,不进入循环或打印最终值,来做到这一点。