zoukankan      html  css  js  c++  java
  • Makefile之字符串函数

    1.subst字符串替换函数

     $(subst <from>,<to>,<text>)
     名称:字符串替换函数——subst。
     功能:把字串<text>中的<from>字符串替换成<to>。
        返回:函数返回被替换过后的字符串。

    例子:

    comma := ,
    empty :=
    space := $(empty) $(empty)
    string := a b c d
    bar :=$(subst $(space),$(comma),$(string))
    all:
            @echo $(bar)

    这里:

    space := $(empty) $(empty)必须是两个空格;否则正常显示效果;

    2.patsubst模式字符串处理函数

    $(patsubst $(pattern),$(replacement),$(text))
      
    函数功能:
      将text中的符合pattern模式的,替换成repacement;
    例子:
      
    3.strip去除开头和结尾的空格符
    $(strip <string>)
    函数功能:
      去除字符串的开头和结尾空格符

    4.findstring查找字符串函数
    $(findstring <find>,<in>)
    函数功能:
      在字符串<in>中,查找<find>字符串;
    如果找到,则返回<find>字符串;
    否则,返回空字符串;

    5.filter过滤函数
    $(filter <pattern...>,<text>)
    函数功能:
      以<pattern..>模式过滤<text>字符串中的单词,保留符合模式的字符串;
    注意:
      这可以有多个模式;
    举例:
    A = 1.c 2.o 3.s 4.h
    B = $(filter %.c %.s,$(A))
    all:
            echo $B

     函数输出:1.c 3.s


    6.filter-out反过滤函数
    函数功能:
      去除符合模式的字符串,返回不符合的字符串
    $(filer-out <pattern...>,<text>)
    举例:
    A = 1.c 2.o 3.s 4.h
    B = $(filter-out %.c %.s,$(A))
    all:
            echo $B
    
    

      函数输出:2.o   4.h


    7.sort排序函数
     函数功能:给单词按照首字母,升序
    举例:
    A = bf dc ca ba ac
    B = $(sort $(A))
    all:
            echo $B
    
    

    函数输出:ac ba bf ca dc

    8.word取单词函数

      $(word <n>,<text>) 

      函数功能:返回text中的第N个单词;从1开始

      举例:

    A = bf dc ca ba ac
    B = $(word 2,$(A))
    all:
            echo $B

    函数返回:dc  也就是第二个字符串;

    9.wordlist取单词串函数

      $(wordlist <s>,<e>,<text>)

    函数功能:

      返回text字符串中,从s开始,到e的所有单词

    举例:

    A = bf dc ca ba ac
    B = $(wordlist 2,4,$(A))
    all:
            echo $B

    函数返回:dc ca ba

    10.words单词个数统计函数

      $(words <text>)

    函数功能:

      统计text中的单词个数

    举例:

      

    11.firstwords返首个单词

      $(firstword <text>)

    函数功能:

      取字符串<text>中的第一个单词

    举例:

    A = bf dc ca ba ac
    B = $(firstword $(A))
    all:
            echo $B

    函数返回:bf



















  • 相关阅读:
    scp远程文件传输
    ssh远程登录
    PHP PDO使用
    Linux引导流程
    Samba服务器搭建
    linux ftp服务器搭建
    NfS服务的搭建
    Discuz! X2.5数据库字典【转载】
    javaSctipt基础
    压缩文件 compress files 以7z 格式及解压 或者别的格式
  • 原文地址:https://www.cnblogs.com/weiyouqing/p/8660388.html
Copyright © 2011-2022 走看看