Note that there are some explanatory texts on larger screens.

plurals
  1. POC# string serializer converted to Qt
    primarykey
    data
    text
    <p>I have this </p> <pre class="lang-cs prettyprint-override"><code> public static string Serialize(List&lt;string&gt; lst) { StringBuilder output = new StringBuilder(""); foreach (var str in lst) { string inter; inter = str.Count().ToString().Count().ToString() + str.Count().ToString() + str; output.Append(inter); } return output.ToString(); } </code></pre> <p>What this code does is if I have a string <code>troy</code> in it, it will return</p> <pre class="lang-cs prettyprint-override"><code>14troy </code></pre> <p>1 being how many digits in the identifier and 4 being the number of characters in the string.</p> <p>Or if I use <code>stackoverflow</code> it will return</p> <pre class="lang-cs prettyprint-override"><code>213stackoverflow </code></pre> <p>2 being the number of digits in the length identifier and 13 being the number of characters in the message.. </p> <p>I'm trying to convert this to Qt code and I don't understand what .Count() is returning. I know it's in System.Linq. </p> <p>I also need to know how I would achieve this in Qt C++. </p> <p>Edit: After getting Tim Meyer's help I figured out how to do it.. He're's the code</p> <pre class="lang-cs prettyprint-override"><code>QString ObjectSerializer::Serialize( QList&lt;QString&gt; lst ) { QString output; foreach( QString str, lst ) { int strLen = str.length(); int identLeng = QString(QString::number(strLen)).length(); output.append( QString( "%1%2%3" ) .arg( identLeng ) .arg( strLen ) .arg( str ) ); } return output; } </code></pre> <p>ALSO if you're interested in the deserializer (does the opposite) here's the code:</p> <pre class="lang-cs prettyprint-override"><code>QList&lt;QString&gt; ObjectSerializer::Deserialize( QString str ) { if(str.isNull() || str.isEmpty()) return QList&lt;QString&gt;(); QList&lt;QString&gt; items; int index = 0; while(index &lt; str.length()) { int indexLen = QString(str[index]).toInt(); index++; QString subStr = str.mid(index, indexLen); int keyLen = subStr.toInt(); index += indexLen; QString key = str.mid(index, keyLen); index += keyLen; items.append(key); } return items; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload