<p>Multistrings (double null-terminated string of null-separated strings) are common in the Windows API. What's a good method for converting a multistring returned from an API to a C# string collection and vice versa?</p>

<p>I'm especially interested in proper handling of character encoding (Windows XP an later).</p>

<p>The following method seems to be okay for creating a multistring, but I don't have an example of decoding a multistring.</p>

<pre><code>static string StringArrayToMultiString(
    ICollection&lt;string&gt; stringArray
    )
{
    StringBuilder multiString = new StringBuilder();


    if (stringArray != null)
    {
        foreach (string s in stringArray)
        {
            multiString.Append(s);
            multiString.Append('\0');
        }
    }

    return multiString.ToString();
}
</code></pre>

This might be naïve, but how about:
```
```
static string[] MultiStringToArray(string multiString)
{
    return multiString.TrimEnd('\0').Split('\0');
}
```
```
Also - aren't you missing the final
```
\0
```
(you state double-null-terminated) in
```
StringArrayToMultiString
```
?
And it might be easier to call if the array was a
```
params string[]
```
array - something like:
```
```
static string StringArrayToMultiString(params string[] values)
{
    if (values == null) throw new ArgumentNullException("values");
    StringBuilder multiString = new StringBuilder();

    foreach (string s in values)
    {
        multiString.Append(s);
        multiString.Append('\0');
    }
    return multiString.ToString();
}
```
```
[edited after clarification about final \0]