How do you use a char* in C#?
-
In C++ I recieved data from a DLLIMPORT call in a char string as follows:
void funct() { char *icy=BASS_StreamGetTags( Channel, BASS_TAG_ICY); for (;*icy;icy+=strlen(icy)+1) { char * lowercase; lowercase = _strlwr(icy); if (!memcmp(icy,"title :",7)) { temp = icy; pCPlayer->WMA_Title = CamelCase(temp.Right(temp.GetLength() - 8)); TRACE("TITLE:"); TRACE( pCPlayer->WMA_Title ); TRACE( "\n"); } if (!memcmp(icy,"author :",8)) { temp = icy; pCPlayer->WMA_Author = CamelCase(temp.Right(temp.GetLength() - 9)); TRACE("AUTHOR:"); TRACE( pCPlayer->WMA_Author ); TRACE( "\n"); } } }
In C# I am returning the data to a string. How do I walk thru the data in a C# string like I did in the above example?
-
In C++ I recieved data from a DLLIMPORT call in a char string as follows:
void funct() { char *icy=BASS_StreamGetTags( Channel, BASS_TAG_ICY); for (;*icy;icy+=strlen(icy)+1) { char * lowercase; lowercase = _strlwr(icy); if (!memcmp(icy,"title :",7)) { temp = icy; pCPlayer->WMA_Title = CamelCase(temp.Right(temp.GetLength() - 8)); TRACE("TITLE:"); TRACE( pCPlayer->WMA_Title ); TRACE( "\n"); } if (!memcmp(icy,"author :",8)) { temp = icy; pCPlayer->WMA_Author = CamelCase(temp.Right(temp.GetLength() - 9)); TRACE("AUTHOR:"); TRACE( pCPlayer->WMA_Author ); TRACE( "\n"); } } }
In C# I am returning the data to a string. How do I walk thru the data in a C# string like I did in the above example?
-
How is the data arranged in the string? What is the separator between the strings in the stream? Is it still a zero character? --- b { font-weight: normal; }
The data is a pointer to a series of null-terminated strings is returned, the final string ending with a double null.
-
The data is a pointer to a series of null-terminated strings is returned, the final string ending with a double null.
If you have that data in a string, just split it on '\x00' and don't use the last two records in the array, as they will be the strings between the last two terminators and between the last terminator and the end of the string. --- b { font-weight: normal; }
-
If you have that data in a string, just split it on '\x00' and don't use the last two records in the array, as they will be the strings between the last two terminators and between the last terminator and the end of the string. --- b { font-weight: normal; }
Well I ended up doing the following. When I used string as the return value I was only getting the first chuck of data and not the rest.
IntPtr icy = BASS_StreamGetTags( radioChan, BASS_TAG_ICY ); byte[] bytetag = new byte[512]; if (icy != IntPtr.Zero) { Marshal.Copy(icy, bytetag, 0, bytetag.Length); } ASCIIEncoding encoding = new ASCIIEncoding( ); string constructedString = encoding.GetString(bytetag); if (constructedString != string.Empty) { string tokenizer = "\x00\0"; string[] token = constructedString.Split( tokenizer.ToCharArray(), 13 ); }
Thanks for your help