X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=common%2FclitkCommon.txx;h=845e62fe520deb89def17b26d99c0e3fa7be1c98;hb=d55f025b18f68066a52b8f33c2dc6481e82c2580;hp=5ee83bdca8f4f3efc23ae2aa8dc12ad28a2fe36e;hpb=da7742b2188d694446ffedc1835b778fb71849b7;p=clitk.git diff --git a/common/clitkCommon.txx b/common/clitkCommon.txx index 5ee83bd..845e62f 100644 --- a/common/clitkCommon.txx +++ b/common/clitkCommon.txx @@ -235,5 +235,22 @@ void MapToVecSecond(const M & m, V & v) { } //-------------------------------------------------------------------- + +//-------------------------------------------------------------------- +//http://stackoverflow.com/questions/1494399/how-do-i-search-find-and-replace-in-a-standard-string +template +int inline findAndReplace(T& source, const T& find, const T& replace) +{ + int num=0; + int fLen = find.size(); + int rLen = replace.size(); + for (int pos=0; (pos=source.find(find, pos))!=T::npos; pos+=rLen) { + num++; + source.replace(pos, fLen, replace); + } + return num; +} +//-------------------------------------------------------------------- + #endif /* end #define CLITKCOMMON_TXX */