1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 \*---------------------------------------------------------------------------*/
29 #include "IOstreams.H"
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 int main(int argc, char *argv[])
38 string test("$HOME kjhkjhkjh \" \\$HOME/tyetyery ${FOAM_RUN} \n ; hkjh ;$");
40 Info<< "string:" << test << nl << "hash:"
41 << unsigned(string::hash()(test)) << endl;
43 // test sub-strings via iterators
44 string::const_iterator iter = test.end();
45 string::const_iterator iter2 = test.end();
46 string::size_type fnd = test.find('\\');
48 if (fnd != string::npos)
50 iter = test.begin() + fnd;
54 Info<< "sub-string via iterators : >";
62 Info<< string(test).replace("kj", "zzz") << endl;
63 Info<< string(test).replace("kj", "") << endl;
64 Info<< string(test).replaceAll("kj", "zzz") << endl;
65 Info<< string(test).replaceAll("kj", "z") << endl;
67 Info<< string(test).expand() << endl;
69 string test2("~OpenFOAM/controlDict");
70 Info<< test2 << " => " << test2.expand() << endl;
72 // replace controlDict with "newName"
74 string::size_type i = test2.rfind('/');
76 if (i == string::npos)
82 // this uses the std::string::replace
83 test2.replace(i+1, string::npos, "newName");
85 Info<< "after replace: " << test2 << endl;
88 // this uses the Foam::string::replace
89 test2.replace("OpenFOAM", "openfoam");
91 Info<< "after replace: " << test2 << endl;
97 string s2(s.expand());
99 cout<< "output string with " << s2.length() << " characters\n";
100 cout<< "ostream<< >" << s2 << "<\n";
101 Info<< "Ostream<< >" << s2 << "<\n";
102 Info<< "hash:" << hex << string::hash()(s2) << endl;
104 Info << "End\n" << endl;
110 // ************************************************************************* //