|
| 1 | +--- |
| 2 | +description: "Learn more about: patsubst, patsubsti NMAKE functions" |
| 3 | +title: "patsubst, patsubsti NMAKE functions" |
| 4 | +ms.date: "9/30/2021" |
| 5 | +helpviewer_keywords: ["patsubst NMAKE function", "patsubsti NMAKE function", "NMAKE function, patsubst", "NMAKE function, patsubsti"] |
| 6 | +monikerRange: '>=msvc-170' |
| 7 | +--- |
| 8 | +# `patsubst`, `patsubsti` NMAKE functions |
| 9 | + |
| 10 | +Evaluates to a list of items with each item that matches a pattern replaced by a substitution, and items that don't match kept as-is. |
| 11 | + |
| 12 | +## Syntax |
| 13 | + |
| 14 | +```makefile |
| 15 | +$(patsubst pattern,replacement,input) |
| 16 | +$(patsubsti pattern,replacement,input) |
| 17 | +``` |
| 18 | + |
| 19 | +### Parameters |
| 20 | + |
| 21 | +*`pattern`*\ |
| 22 | +The [pattern](using-an-nmake-macro.md#function-pattern-syntax) to search for. |
| 23 | + |
| 24 | +*`replacement`*\ |
| 25 | +The [pattern](using-an-nmake-macro.md#function-pattern-syntax) to replace *`pattern`* with. If a wildcard is present in *`replacement`*, then it will be replaced with the text that the wildcard in *`pattern`* matched. |
| 26 | + |
| 27 | +*`input`*\ |
| 28 | +The [list](using-an-nmake-macro.md#function-list-syntax) of items to be replaced or kept. |
| 29 | + |
| 30 | +## Return value |
| 31 | + |
| 32 | +Returns *`input`*, but each item that matches *`pattern`* is replaced by *`replacement`*. Items that don't match *`pattern`* are kept as-is. |
| 33 | + |
| 34 | +## Remarks |
| 35 | + |
| 36 | +`patsubsti` is the case-insensitive version of `patsubst`. |
| 37 | + |
| 38 | +## Example |
| 39 | + |
| 40 | +```makefile |
| 41 | +$(patsubst He%,_%_,Hello Hey Hi) # Evaluates to "_llo_ _y_ Hi" |
| 42 | +# "He" matches "Hello" and "Hey", and so "llo" and "y" are matched by the wildcard |
| 43 | +# and used to substitute the wildcard in the replacement. "Hi" is not matched and so is kept as-is |
| 44 | + |
| 45 | +$(patsubst Hi,Bye,Hello Hey Hi) # Evaluates to "Hello Hey Bye" - No wildcard is required |
| 46 | +$(patsubst %lo,Bye,Hello Hey Hi) # Evaluates to "Bye Hey Hi" |
| 47 | +# A wildcard can be used in the pattern without a wildcard in the replacement |
| 48 | + |
| 49 | +$(patsubst he%,_%_,Hello Hey Hi) # Evaluates to "Hello Hey Hi" - patsubst is case-sensitive, so no substitutions performed |
| 50 | +$(patsubst he%,_%_,Hello Hey Hi) # Evaluates to "_llo_ _y_ Hi" - patsubsti is case-insensitive |
| 51 | + |
| 52 | +# patsubsti is commonly used to change the file extensions of a list of files |
| 53 | +OBJ_FILES=$(patsubst %.c,%.obj,$(C_SOURCES)) $(patsubst %.cpp,%.obj,$(patsubst %.cxx,%.obj,$(CPP_SOURCES))) |
| 54 | +``` |
| 55 | + |
| 56 | +## See also |
| 57 | + |
| 58 | +[Macros and NMAKE](macros-and-nmake.md)\ |
| 59 | +[NMAKE functions by category](using-an-nmake-macro.md#functions-by-category) |
0 commit comments