Is it possible to get a char* for a string variable in C#?
I need to convert a path string to a char* for using some native win32 function ...
This last part of the definition is important: all C-strings are char arrays, but not all char arrays are c-strings. C-strings of this form are called “string literals“: const char * str = "This is a string literal.
Instead of using arrays, we can use character pointers to store a string value.
char* is a pointer to a character. char is a character. A string is not a character. A string is a sequence of characters.
Well you could certainly do this:
string str = "my string";  unsafe  {     fixed (char* p = str)     {                        // do some work     } }   where there is an operator (char*) bound to the string object. However, the output format may not be compatible with the underlying C or other format... this is however quite a good solution to parse the string. Hope it's helpful for anybody who reads this post.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With