From e9f8a5eb254edc78a22e56eb1c48fa8c6569e69e Mon Sep 17 00:00:00 2001 From: Nuno Jesus Date: Mon, 31 Jul 2023 20:14:10 +0100 Subject: [PATCH] README: added findstring function section. --- README.md | 42 +++++++++++++++++++++++++++-- code/18-findstring-example/Makefile | 6 +++++ 2 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 code/18-findstring-example/Makefile diff --git a/README.md b/README.md index ffe6f75..0a8381b 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,8 @@ It starts with a beginner's guide, followed up by some medium-advanced concepts. @@ -1088,7 +1090,7 @@ BAR=a,b,c ### A4.2 - Functions for String Manipulation -
+

patsubst

- replaces string patterns
``` @@ -1165,11 +1167,38 @@ RESULT == a b c ```
+
+

findstring

- looks for occurrences of a string
+ +``` +$(findstring find,in) +``` + +If the text `in` contains a word identical to `find`, the function returns `find`. Otherwise, it returns the empty string. + +Here's an example ([code/18-findstring-example](code/18-findstring-example)): + +```Makefile +NAME = Nuno Jesus + +all: + echo Result=$(findstring Jesus, $(NAME)) + echo Result=$(findstring Miguel, $(NAME)) +.SILENT: +``` + +Output: + +``` +Result=Jesus +Result= +``` + +