以二进制格式保存字符串数组
string value1 , value1 ;
int length1 , length2 ;
System.Collections.BitArray bitValue1 = new System.Collections.BitArray(Length1);
System.Collections.BitArray bitValue2 = new System.Collections.BitArray(Length2);
我正在寻找将每个字符串转换为具有定义长度的 BitArray 的最快方法(如果字符串大于定义的长度,则应修剪该字符串,如果字符串大小较小,则剩余位将填充 false),然后将这两个字符串放在一起并写入一个二进制文件中。
编辑 : @dtb:一个简单的例子可以是这样的 value1 = "A" ,value2 = "B" 和 length1 =8 和 length2 = 16 ,结果将是 010000010000000001000010 前 8 位来自“A”,接下来的 16 位来自“B”
string value1 , value1 ;
int length1 , length2 ;
System.Collections.BitArray bitValue1 = new System.Collections.BitArray(Length1);
System.Collections.BitArray bitValue2 = new System.Collections.BitArray(Length2);
I'm looking for the fastest way to covert each string to BitArray with defined length for each string (the string should be trimmed if it is larger than defined length and if strings size is smaller remaining bits will be filled with false) and then put this two strings together and write it in a binary file .
Edit :
@dtb : a simple example can be like this value1 = "A" ,value2 = "B" and length1 =8 and length2 = 16 and the result will be 010000010000000001000010
the first 8 bits are from "A" and next 16 bits from "B"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我要继续说,这假设 ASCII 字符,因此任何高于 ASCII 127 的内容(例如简历中的 é)都会崩溃,并可能返回 ASCII 63,即问号。
And I'm going to keep saying it, this assumes ASCII characters so anything above ASCII 127 (such as the é in résumé) will freak out and probably return ASCII 63 which is the question mark.
将字符串转换为其他内容时,您需要考虑要使用的编码。 的版本
这是使用 UTF-8 编辑
嗯...看到您正在寻找 BitArray 而不是 ByteArray,这可能对您没有帮助。
When converting a string to something else you need to consider what encoding you want to use. Here's a version that uses UTF-8
Edit
Hmm... saw that you're looking for a BitArray and not a ByteArray, this won't help you probably.
由于这不是一个非常明确的问题,尽管如此,我还是会尝试一下,
这是您想要实现的目标吗?
希望这有帮助,
此致,
汤姆.
Since this is not a very clear question I'll give this a shot nonetheless,
Is that what you are trying to achieve?
Hope this helps,
Best regards,
Tom.