1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 \*---------------------------------------------------------------------------*/
30 #include "IOstreams.H"
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 int main(int argc, char *argv[])
39 string test("$HOME kjhkjhkjh \" \\$HOME/tyetyery ${FOAM_RUN} \n ; hkjh ;$");
41 Info<< "string:" << test << nl << "hash:"
42 << unsigned(string::hash()(test)) << endl;
44 // test sub-strings via iterators
45 string::const_iterator iter = test.end();
46 string::const_iterator iter2 = test.end();
47 string::size_type fnd = test.find('\\');
49 if (fnd != string::npos)
51 iter = test.begin() + fnd;
55 Info<< "sub-string via iterators : >";
63 Info<< string(test).replace("kj", "zzz") << endl;
64 Info<< string(test).replace("kj", "") << endl;
65 Info<< string(test).replaceAll("kj", "zzz") << endl;
66 Info<< string(test).replaceAll("kj", "z") << endl;
68 Info<< string(test).expand() << endl;
70 string test2("~OpenFOAM/controlDict");
71 Info<< test2 << " => " << test2.expand() << endl;
73 // replace controlDict with "newName"
75 string::size_type i = test2.rfind('/');
77 if (i == string::npos)
83 // this uses the std::string::replace
84 test2.replace(i+1, string::npos, "newName");
86 Info<< "after replace: " << test2 << endl;
89 // this uses the Foam::string::replace
90 test2.replace("OpenFOAM", "openfoam");
92 Info<< "after replace: " << test2 << endl;
98 string s2(s.expand());
100 cout<< "output string with " << s2.length() << " characters\n";
101 cout<< "ostream<< >" << s2 << "<\n";
102 Info<< "Ostream<< >" << s2 << "<\n";
103 Info<< "hash:" << hex << string::hash()(s2) << endl;
105 Info << "End\n" << endl;
111 // ************************************************************************* //