Reputation: 277
To Extract part of a string in a given line:
Given line is:
D:\AB554P_Itr23\ModelDir\AB554P_approximation_NodeData.dat Read 3/18/2010
I need to extract only the file name AB554P_approximation_NodeData.dat
. I am using CodeGear RAD Studio C++ Builder. Thanks:)
Upvotes: 1
Views: 5915
Reputation: 1854
string s = "D:\AB554P_Itr23\ModelDir\AB554P_approximation_NodeData.dat Read 3/18/2010";
size_t pos;
pos = s.find(" ");
s.erase(pos);
Now call split
for '\' to split the remaining part.
Upvotes: 1
Reputation: 145204
In order to handle Windows paths, use the Windows API path functions, such as PathFindFileName
.
Cheers & hth.,
Upvotes: 1
Reputation: 612794
The RTL function ExtractFileName()
will extract the file name from a path.
Exactly how to split the 3 fields in your example depends very much on what the rules are for forming that line of text. How is it delimited? Is is delimited by spaces? If so, how do you escape spaces in the file path? Until you specify that information, that part of your question is unanswerable.
Upvotes: 3
Reputation: 53496
How about Boost::Filesystem...
string name = path( "D:\\AB554P_Itr23\\ModelDir\\AB554P_approximation_NodeData.dat").filename()
Upvotes: 4
Reputation: 272467
You may want to investigate a regular expression library, such as Boost Regex.
Upvotes: 0