mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: add string replaceAny() method
- takes a search string and a replacement character.
The replacement character can also be a nul char ('\0'), which
simply removes the characters.
Possible uses:
* Replace reserved characters
str.replaceAny("<>:", '_');
* Remove shell meta-characters or reserved filesystem characters
str.replaceAny("*?<>{}[]:", '\0');
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2013 OpenFOAM Foundation
|
||||
Copyright (C) 2016-2019 OpenCFD Ltd.
|
||||
Copyright (C) 2016-2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -173,6 +173,19 @@ int main(int argc, char *argv[])
|
||||
Info<<"trimRight: " << stringOps::trimRight(test) << endl;
|
||||
Info<<"trim: " << stringOps::trim(test) << endl;
|
||||
|
||||
// With replace, replaceAll
|
||||
{
|
||||
string test2(test);
|
||||
Info<<"replaceAny: (\"abcj\", '?')" << nl
|
||||
<< test2.replaceAny("abcj", '?') << endl;
|
||||
Info<<"replaceAll: (\"k\", \"?\")" << nl
|
||||
<< test2.replaceAll("k", "?") << endl;
|
||||
Info<<"replaceAll: (\"h\", null) - ie, remove them" << nl
|
||||
<< test2.replaceAll("h", "") << endl;
|
||||
Info<<"replaceAny: (\"it${}?\", null) - ie, remove them" << nl
|
||||
<< test2.replaceAny("it${}?", '\0') << endl;
|
||||
}
|
||||
|
||||
if (false)
|
||||
{
|
||||
Info<<"test move construct - string size:" << test.size() << nl;
|
||||
|
||||
Reference in New Issue
Block a user