replace(char) String function? [SOLVED]
-
On 26/10/2014 at 04:12, xxxxxxxx wrote:
Please note that the replacement of the forward slash to a back slash in an url is only necessary on non-Unix systems (-> Windows).
If you apply this conversion (of the slashes) to a Unix compatible system (OS X, Linux) then you create a wrong Filename that won't work.
Best regards,
Wilfried
-
On 26/10/2014 at 04:14, xxxxxxxx wrote:
Andreas is absolutely right, just keep it simple and forget all that regular expression stuff. It doesn't need it for something so very simple.
-
On 26/10/2014 at 07:08, xxxxxxxx wrote:
My code works just fine for me. And I didn't need to enable exceptions. Or do anything special for regex to work Andreas.
All I did was #include <regex>. And then wrote the code I posted.
I'm still using VS2010 most of time. I don't know if that matters?Thanks for posting your version though.
-ScottA
-
On 26/10/2014 at 07:13, xxxxxxxx wrote:
Scott,
I think this matters, as it may not warn about this with older compiler versions (or if you are lucky the old standard lib doesn't use exceptions for regex).
I can only stress my words, I disadvise to use any external libraries which may need or make use of exceptions. We won't be able to help, if you run into problems with such stuff.
Of course there are cases you will need to use external libraries, I fully understand. All I'm saying, I wouldn't do so, if there's no need for it. -
On 26/10/2014 at 07:17, xxxxxxxx wrote:
One question to the community, as Scott says, his code is working as posted. How does the following loop help to eliminate the "file:///" prefix, I don't get it?
for(LONG i=0; i<8; i++) { c4dURLresult = '\n'; }
-
On 26/10/2014 at 07:17, xxxxxxxx wrote:
Ok. Thanks.
I'm very comfortable using the STL in my code but...Originally posted by xxxxxxxx
I'd prefer to stick to using the SDK as much as possible. __
-ScottA
-
On 26/10/2014 at 07:19, xxxxxxxx wrote:
-
On 26/10/2014 at 11:40, xxxxxxxx wrote:
Actually. That for() loop does NOT work properly.
The C4D console reports that it does...But it's evil. It's lying to us. !Evil Smile
[URL-REMOVED]
The C4D console does not show the correct carriage returns, like the VS console does (it removes them).
I'm glad you mentioned it Andreas. Because I would have wondered what the heck was going on later when I used the returned string.This should work better when using the STL regex class.
But I'm going to use your SDK based code instead.#include <regex> void htmlViewerCallback(void *user_data, const String &url, LONG encoding, void *reserved) { //Prints the path to the webpage in the console when the hyperlink is clicked on //This takes some time because it fetches the webpage..that's why a callback function is required //GePrint(url); //The url string value returned is formatted with %20 for spaces. And forward leaning slashes //So this is how to convert it to a normal Windows file path type string result CHAR buffer[1024]; //First convert the forward leaning slashes to backwards leaning slashes url.GetCString(buffer, sizeof(buffer)); std::string stlurl = buffer; std::tr1::regex rx1("/"); std::string replacement1 = "\\"; std::string result1 = std::tr1::regex_replace(stlurl, rx1, replacement1); //Next replace the %20 instances with spaces std::string stlur2 = result1; std::tr1::regex rx2("%(..)"); std::string replacement2 = " "; std::string result = std::tr1::regex_replace(stlur2, rx2, replacement2); //Now we need to delete the file:/// crap at the start of the url string for(int i=0; i<8; i++) { result.erase(result.begin()); } //The url converted to a regular filename String c4dURLresult = result.c_str(); GePrint(c4dURLresult); }
Thanks for the help guys,
-ScottA
[URL-REMOVED] @maxon: This section contained a non-resolving link which has been removed.
-
On 26/10/2014 at 13:09, xxxxxxxx wrote:
I marked this solved.
Yet, I want to emphasize Wilfried's post. You'll have to care for more systems but Windows. -
On 27/10/2014 at 09:13, xxxxxxxx wrote:
Btw, there's std::string::substr() and String::SubStr(). Easier to read and by far more efficient than
erasing the first character in a for loop.