Greetings
Can you please tell me how to convert an incomprehensible Text format from textbox to MSVS2010 into a standard array of chars. C ++ language Windows Forms project
Thank!
Greetings
Can you please tell me how to convert an incomprehensible Text format from textbox to MSVS2010 into a standard array of chars. C ++ language Windows Forms project
Thank!
(I’ll try to get my finger into the sky, because, apparently, you are developing with C++/CLI , but I could be wrong)
TextBox has property Text :
virtual property String^ Text { String^ get () override; void set (String^ value) override; } That is, turning to textBox->Text , you get a variable of type String^ .
The correct conversion from String^ to the char array is not the most trivial operation, since String^ is an abstraction much wider than char[] . Correctly this conversion operation is performed like this:
IntPtr initialStringPtr = Marshal::StringToHGlobalAnsi(initialString); char* converted = static_cast<char*>(initialStringPtr.ToPointer()); // Работаете с 'converted'. Marshal::FreeHGlobal(initialStringPtr); // После этой строчки указатель 'converted' указывает на освобожденный участок памяти! I recommend to think 300 times (and then think 300 more times) before moving from a convenient unicode string implementation to char* .
Source: https://ru.stackoverflow.com/questions/109164/
All Articles