本文介绍了将字节数组附加到包含'\0'的其他数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有这个函数,它将一个字节数组附加到另​​一个字节数组 但是当源包含'\0'时会出现问题 这是什么我有:I have this function which append an array of byte to an other array of bytesbut the problem appears when the source contains '\0'this what I have :private void Aes_Strcat(sbyte[] a_pchResult, sbyte[] pchResult, int m_iBlockSize) { int x = 0; while (a_pchResult[x] != 0) { x++; } Buffer.BlockCopy(pchResult, 0, a_pchResult, x, m_iBlockSize); } 这里当a_pchResult包含例如{-10,15,3,45,17,25,0 ,53,51,12,0,0,0,0,0,0} 我想在最后添加pchResult(这意味着在'12'元素之后) 但正如你所说它会在'25'之后添加它,因为它在结束前找到'0'。 任何想法如何知道最后一个位置,如果它包含'\0'元素,则在源数组的末尾添加新数组。here when the a_pchResult contains for example { -10, 15,3,45,17,25,0,56,41,12,0,0,0,0,0,0}and I want to add pchResult to it at the end (it means after the '12' element)but as you say it will add it after '25' because it find the '0' before the end.any idea how know the last position to add the new array at the end of source array if it contains '\0' element.推荐答案int length = //...sbyte[] array = new sbyte[length];//...for (int index = 0; index < array.Length; ++index) { // array.Length == length} 类似的事情适用于排名较高的数组,不具有零基数的数组(参见 Array.GetLowerBound , Array.GetUpperBound ),依此类推: https://msdn.microsoft.com/en-us/library /system.array%28v=vs.110%29.aspx [ ^ ], HTTPS://msdn.microso ft.com/en-us/library/system.array.getlowerbound(v=vs.110).aspx [ ^ ], https://msdn.microsoft.com/en-us/library/system.array.getupperbound (v = vs.110).aspx [ ^ ]。 -SASimilar thing goes for arrays of higher rank, arrays with not zero-base indices (see Array.GetLowerBound, Array.GetUpperBound), and so on:https://msdn.microsoft.com/en-us/library/system.array%28v=vs.110%29.aspx[^],https://msdn.microsoft.com/en-us/library/system.array.getlowerbound(v=vs.110).aspx[^],https://msdn.microsoft.com/en-us/library/system.array.getupperbound(v=vs.110).aspx[^].—SA 这篇关于将字节数组附加到包含'\0'的其他数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-05 18:45
查看更多