C#中的Pascal字符串 [英] Pascal strings in C#

查看:233
本文介绍了C#中的Pascal字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C#开发音频库,并且正在开发WAVE文件格式的ATM。根据我所使用的非常有用的网站的说法,WAVE使用Pascal样式字符串。我已经使用Google搜索超过20分钟,并且只提出了 C到Pascal转换器

I'm working on an audio library in C# and am working on the WAVE file format ATM. According to the very informative website that I am using, WAVE using Pascal style strings. I have been Googling for over 20 minutes and have come up only with a C to Pascal converter.

我知道Pascal和C字符串的比较(C代码):

I know how Pascal and C strings compare (C code):

char *cStr = "Test"; // C - produces {'T', 'e', 's', 't', '\0'}
char pascal[] = {4, 'T', 'e', 's', 't'}; // Pascal

如果有帮助,我正在使用 System.IO.BinaryReader 来分析文件。

If it helps, I am using System.IO.BinaryReader to parse the file.

推荐答案

如果使用 BinaryReader 这应该很容易。

Well if you are using BinaryReader this should be pretty easy.

var size = rd.ReadByte();
var body = rd.ReadBytes(size);
var text = System.Text.Encoding.ASCII.GetString(body);

这篇关于C#中的Pascal字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆