Yup, I'm a newbie.
I've looked up some of the functions, but I can't seem to put them together. Could someone lay it all out in simple terms?
Yup, I'm a newbie.
I've looked up some of the functions, but I can't seem to put them together. Could someone lay it all out in simple terms?
What do you mean by truncate a URL to a file name?
Processing error: Stupidity detected.
------------------------------
Dr. Bebop
Windows XP Professional Ed.
Microsoft Visual Studio 6
if truncate is the same as concatenation. look up strcat(.....) found in string.h
Couldn't think of anything interesting, cool or funny - sorry.
Sorry. I'm trying to write a simple wget frontend (common newbie project, I suspect). I have a full url stored in a string, and I need to reduce it to just the filename:Originally posted by Dr. Bebop
What do you mean by truncate a URL to a file name?
http://www.host.com/pic01.jpg
to
pic01.jpg
As I said, I know it has something to do with reading the string backwards and finding the '/'; but I can't quite sort it out.
Thanks.
If it's a C string you can use the functions in <cstring>.
Code:#include <iostream> #include <cstring> using namespace std; int main() { char *URL = "http://www.host.com/pic01.jpg"; char *file_name; file_name = strrchr( URL, '/' ) + 1; cout<< file_name <<endl; return 0; }
Processing error: Stupidity detected.
------------------------------
Dr. Bebop
Windows XP Professional Ed.
Microsoft Visual Studio 6
Should consider the case when there are more than one"/" in the URL, I did similar thing in a project on linux. I used GnuString,which is very easy.
As to the standard C++, just search for the last "/" then you got the file name
Thanks Dr. Bebop. Works great. I was thinking I'd need two functions, one to find the position of / and the other to do the truncation; so I was completely barking up the wrong tree.
crystalike: You're right, I should have chosen a better example. However, strrchr() does work with longer URL's, so I guess it must read the string backwards.