Jump to content

  • Log In with Google      Sign In   
  • Create Account

Problem with strings


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Chris528   Members   -  Reputation: 186

Like
0Likes
Like

Posted 15 July 2013 - 12:52 AM

I've been working on an awesomium app, and have run into a bit of a problem with strings.
Here's an example
int currentconfig = configsHandle->currentConfig;
char gamedir[260];
//_snprintf(gamedir, sizeof(gamedir),"$('#gamedata0').val('%s');",configsHandle->m_Configs[currentconfig]->m_gamedir);
_snprintf(gamedir, sizeof(gamedir),"$('#gamedata0').val('%s');","f:\\\\what\\\\the\\\\f#$&.fgd");
//printf("the gamedir is: %s\n",gamedir);
MessageBoxA(0,gamedir,"message",MB_OK);
caller->ExecuteJavascript(WSLit(gamedir),WSLit(""));
My problem is this, f:\\\\what\\\\the\\\\f#$&.fgd evaluates to f:\\what\\the\\f#$&.fgd for the messagebox, while on the html element #gamedata0 it shows up as f:\what\the\f#$&.fgd
 
How would i go about getting configsHandle->m_Configs[currentconfig]->m_gamedir converted to something that will show up correctly in the html?

Sponsor:

#2 Dragonsoulj   Crossbones+   -  Reputation: 2111

Like
0Likes
Like

Posted 15 July 2013 - 02:42 AM

Since 4 slashes translates to 2 in what looks like C (or C++), and then translates to 1 in HTML, perhaps it is because storing in gamedir stores 2 slashes next to each other instead of 4 because the slash is an escape character, and when passed along, it looks like second escape set, so it escapes it again.

 

\\\\ -> \\
\\ -> \


#3 Chris528   Members   -  Reputation: 186

Like
0Likes
Like

Posted 15 July 2013 - 12:56 PM

Thanks, that verifies what I was thinking. Earlier this morning I figured that I should use a function to replace all "\\" with "\\\\". A quick google search came up with this http://stackoverflow.com/questions/779875/what-is-the-function-to-replace-string-in-c and it worked perfectly

Edited by Chris528, 15 July 2013 - 12:56 PM.


#4 Trienco   Crossbones+   -  Reputation: 2174

Like
1Likes
Like

Posted 15 July 2013 - 10:27 PM

Which is why a / should be used as a path separator whenever possible (yes, even on Windows). There are extremely few cases where it won't work.


f@dzhttp://festini.device-zero.de




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS