473,386 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

System.String conversion to System.Char*

Hi!

I've got a problem when converting a System.String into a System.Char*!
Problem: Invalid Cast Operation
Here is the source:

Type type = Type.GetType("System.Char*");
String val = "c";
Object o = Convert.ChangeType(val,type);

val can only be a string, because i'm reading it out of an xml-file!
Xml-Source:
<type>System.Char*</type>
<value>c</value>

I hope you can help me! Thank you ;)

Eva
Nov 15 '05 #1
4 3991
Eva,

What do you need a char* for? Anyway, you use the fixed statement for
that

fixed ( char* pc = val ) { ... }

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 15 '05 #2
Hi Mattias!

Thanks for your fast answere! I am developing a programm to store and
load classes/instances/methods... I store values for methods(according
to their MethodInfo)and for testing purpose i tried to construate a
System.String with the constructor String(Char*, int, int)! Creating and
storing works fine, but reloading does not work!
The method to reload a Value looks like this(Xml-Data see above):

private object GenerateValue(XmlElement element)
{
//Get Type
XmlNodeList xnl = element.GetElementsByTagName("type");
Type valType = Type.GetType(xnl.Item(0).InnerText);
//Get Value
xnl = element.GetElementsByTagName("value");
String value = xnl.Item(0).InnerText;
//Generate Value
return Convert.ChangeType(value,valType);
}

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #3
Thanks for your fast answere! I am developing a programm to store and
load classes/instances/methods...
Any reason you're not using the framework's serialization support for
this?

//Generate Value
return Convert.ChangeType(value,valType);


The Convert class and its ChangeType method is pretty limited in which
types it can handle and what kinds of conversion. You can't expect it
to work for any value you've persisted.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 15 '05 #4
>Any reason you're not using the framework's serialization >support for
this?

Yes, the structure of the programm is too complicated and can't be
simplified to use xml-serialisation!
I already tried it, but it doesn't work out quite properly!

Ok! Thanks for your information! It seems that problem is far more
complicated, than it seemed at first ;) I'll have to work on that ;)

Eva

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Marcin Kalicinski | last post by:
Why string literals are regarded as char * not as const char *? (1) void f(char *); (2) void f(const char *); f("foo") will call version (1) of function f. I understand that the exact type...
7
by: john | last post by:
On my form i have a message box called txtItemDesc that displays the french phrase qualité Père Noël. Now then when i run this code on that text box: Dim chrArr() As Char chrArr =...
11
by: Zordiac | last post by:
How do I dynamically populate a string array? I hope there is something obvious that I'm missing here Option Strict On dim s() as string dim sTmp as string = "test" dim i as integer ...
10
by: Herby | last post by:
I seem to be having a problem with System namespace. There seem to two System namepaces when viewing through Object browser within .NET 2005. One global System:: Then one under <mscorlib> Each...
6
by: karthi | last post by:
hi, I need user defined function that converts string to float in c. since the library function atof and strtod occupies large space in my processor memory I can't use it in my code. regards,...
24
by: Marcus Kwok | last post by:
Hello, I am working on cleaning up some code that I inherited and was wondering if there is anything wrong with my function. I am fairly proficient in standard C++ but I am pretty new to the .NET...
2
by: Alejandro Aleman | last post by:
Hello! i know this may be a newbie question, but i need to convert a string from System::String^ to char*, in the msdn page tells how, but i need to set to /clr:oldSyntax and i dont want it...
3
by: Kevin Frey | last post by:
I am porting Managed C++ code from VS2003 to VS2005. Therefore adopting the new C++/CLI syntax rather than /clr:oldSyntax. Much of our managed code is concerned with interfacing to native C++...
6
by: DaTurk | last post by:
Hi, I have several interfaces in CLI that I access via c#. My problem is, is that down in the unmanaged c++, which the CLI lies on top of, I have a lot of c_str() happening. But all of my...
8
by: Edson Manoel | last post by:
I have some C++ unmanaged code that takes std::string& arguments (as reference), and fills them (possibly growing the string). I want to call this code through PInvoke (DllImport), possibly using...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.