Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

stringbuilder to string[]

Status
Not open for further replies.

murrayja

Programmer
May 6, 2000
90
0
0
US
I am using the kernel function to read dot-ini sections and section values. The function ReadPrivateProfileSection returns a 'stringbuilder' value which is a series of strings representing the key=value items of the section as strings (null terminated) and terminated with a final null. I want to get this stringbuilder result into a C# string[] but casting fails.
Any ideas?
 
If it is truly a StringBuilder object that is returned, a simple .ToString() should suffice:
string myvalue = stringbuilder.ToString();

Cheers,
MakeItSo

“Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family.” (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.
 
It is indeed a stringbuilder that is returned as my post states. The stringbuilder object returned is a series of strings so that 'stringbuilder.tostring()' returns only the first of several returned catenated strings. EG if I had three lines in the section with the values 'a', 'b', 'c' the stingbuilder object returned would be a,\0,b,\0,c,\0,\0 and the tostring method returns "a". I have written my own code to extract the section values so, thanks for trying.
 
Code:
[COLOR=#0000FF]string[/color][] parts = stringBuilder.ToString().Split([COLOR=#A31515]'\0'[/color]);

If it is a native string builder and not some custom object that should work..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top