3

In C++ I have some strings, for example string str = "a\0b\0c";

And I need to pass this string to C# without losing data after "\0",and from c# pass to C++ also without losing data.

Can you help me?

Kiroxas
  • 891
  • 10
  • 24
Pavlo Denys
  • 81
  • 1
  • 6

1 Answers1

0

Ok, I found answer for my question.Maybe, it`s not very good solution, but it fix my problem. C++:

string EncodeConfigString(string OptionsString)
{
string tempOptions = " ";
if (OptionsString.size() != 0)
{
    vector<int> arrayOfIntCodes;

    for (int i = 0; i < OptionsString.size(); i++)
    {
        int codeOfChar = OptionsString[i];
        tempOptions += std::to_string(codeOfChar) + "&";
    }
}

return tempOptions;
}

C#:

  private string DecodeConfig(StringBuilder OptionsBuilder)
    {
        string result = String.Empty;
        string Options = OptionsBuilder.ToString();

        if (!string.IsNullOrEmpty(Options) && Options.Contains(Consts.AMPERSAND))
        {
            string[] entries = Options.Split(Consts.AMPERSAND);

            StringBuilder chars = new StringBuilder(Consts.OUTPUT_MAX_SIZE);

            for (int i = 0; i < entries.Length; i++)
            {
                int resultParse;

                if (int.TryParse(entries[i], out resultParse))
                {
                    chars.Append((char)resultParse);
                }
            }

            result = chars.ToString();
        }

        return result;

    }
Pavlo Denys
  • 81
  • 1
  • 6