visual c++ - Convert all instances of "\" to "\\" in System::String^ and convert to char* -


i have openfiledialog returns filename. want save filename char* can open later using fstream. i'll need replace instances of \ \\ in string.

my tactic doing split system::string^ on every instance of \, , join elements of resulting system::string^ array \\ separating them.

this function have written, seems return blank string when pass string^ contains \.

private: const char* getcharpointer(string^ name){      array<string^>^ words;     string^ delimstr = "\\";     array<char>^ delimiter = delimstr->tochararray( );     string^ replacedelim = "\\\\";      words = name->split(delimiter);      string^ tidiedname = string::join( replacedelim, words );     label1->text = tidiedname;     std::string newname=msclr::interop::marshal_as< std::string >( tidiedname);      const char* name_cstr = newname.c_str();      return name_cstr; } 

i newcomer visual c++ , windows in general appreciate pointers on this. doesn't intellisense doesn't seem work visual studio 2010.

intellisense not provided in vc++ , seems never added vc++. anyway, can use, instead of join, replace.
can see here reference.

look @ simple program [ i'm using windows form application , code under button event handler].

string^ = "hello\\world";  string^ b = a->replace("\\", "\\\\"); //replace \ \\ messagebox::show(a + " -> " + b); 

if run it, output.

hello\world -> hello\\world 

i hope 1 need code!


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -