• halcon分离路径名称


    用haclon程序将目录名分离的算法。

    ParseFileName:='F:/D705/4-20/缺陷/81.bmp'

     parse_filename(ParseFileName, BaseName, Extension, Directory)

    * This procedure gets a filename (with full path) as input
    * and returns the directory path, the base filename and the extension
    * in three different strings.
    * 
    * In the output path the path separators will be replaced
    * by '/' in all cases.
    * 
    * The procedure shows the possibilities of regular expressions in HALCON.
    * 
    * Input parameters:
    * FileName: The input filename
    * 
    * Output parameters:
    * BaseName: The filename without directory description and file extension
    * Extension: The file extension
    * Directory: The directory path
    * 
    * Example:
    * basename('C:/images/part_01.png',...) returns
    * BaseName = 'part_01'
    * Extension = 'png'
    * Directory = 'C:\images\' (on Windows systems)
    * 
    * Explanation of the regular expressions:
    * 
    * '([^\\/]*?)(?:\.[^.]*)?$':
    * To start at the end, the '$' matches the end of the string,
    * so it is best to read the expression from right to left.
    * The part in brackets (?:\.[^.}*) denotes a non-capturing group.
    * That means, that this part is matched, but not captured
    * in contrast to the first bracketed group ([^\\/], see below.)
    * \.[^.]* matches a dot '.' followed by as many non-dots as possible.
    * So (?:\.[^.]*)? matches the file extension, if any.
    * The '?' at the end assures, that even if no extension exists,
    * a correct match is returned.
    * The first part in brackets ([^\\/]*?) is a capture group,
    * which means, that if a match is found, only the part in
    * brackets is returned as a result.
    * Because both HDevelop strings and regular expressions need a '\'
    * to describe a backslash, inside regular expressions within HDevelop
    * a backslash has to be written as '\\'.
    * [^\\/] matches any character but a slash or backslash ('\' in HDevelop)
    * [^\\/]*? matches a string od 0..n characters (except '/' or '\')
    * where the '?' after the '*' switches the greediness off,
    * that means, that the shortest possible match is returned.
    * This option is necessary to cut off the extension
    * but only if (?:\.[^.]*)? is able to match one.
    * To summarize, the regular expression matches that part of
    * the input string, that follows after the last '/' or '\' and
    * cuts off the extension (if any) after the last '.'.
    * 
    * '\.([^.]*)$':
    * This matches everything after the last '.' of the input string.
    * Because ([^.]) is a capturing group,
    * only the part after the dot is returned.
    * 
    * '.*[\\/]':
    * This matches the longest substring with a '/' or a '\' at the end.
    * 
    tuple_regexp_match (FileName, '.*[\\/]', DirectoryTmp)
    tuple_substr (FileName, strlen(DirectoryTmp), strlen(FileName) - 1, Substring)
    tuple_regexp_match (Substring, '([^\\/]*?)(?:\.[^.]*)?$', BaseName)
    tuple_regexp_match (Substring, '\.([^.]*)$', Extension)
    * 
    * 
    * Finally all found backslashes ('\') are converted
    * to a slash to get consistent paths
    tuple_regexp_replace (DirectoryTmp, ['\\','replace_all'], '/', Directory)
    return ()
  • 相关阅读:
    Java版MD5加密算法
    【Struts2复习知识点四】Path路径问题
    IE7与IE8浏览器下session cookie的共享问题以及区别
    【Struts2复习知识点八】DomaimModel域模型接收参数
    Activity class {package/class} does not exist及Unable to start activity ComponentInfo 解决方法
    【Struts2复习知识点二】namespace的配置
    【Struts2复习知识点五】ActionMethod 动态指定调用方法
    【Struts2复习知识点一】配置struts2环境
    JS面向对象编程
    【Struts2复习知识点三】Action的配置
  • 原文地址:https://www.cnblogs.com/supercxm/p/8966813.html
Copyright © 2020-2023  润新知