将char [32]转换为字符串 [英] Convert char[32] to string
问题描述
即时转换字符串中的字符
\0\0\ 0 \ 0 \ 0 \ 0 \ 0 \ 0? ?; \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ >
那么写数据会怎么样
i想要这种类型的数据2018-03-12 16.16.25?
我尝试了什么:
i m converting the char in string
\0\0\0\0\0\0\0\0??;\b\0\0\0\0?????qUw?g?\u0001\0\0\0\0 its not humman readable data.
so what will be do for write Data
i want this type of data 2018-03-12 16.16.25 ?
What I have tried:
public struct PLAT_SUBSCRIBE_EVENT_V20
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)] public char[]
szAlarmTime;
}
public void CB_SubscribeEvent(PLAT_SUBSCRIBE_EVENT_V20 pstEvent, IntPtr pUser)
{
byte[] _szAlarmTime = Encoding.Default.GetBytes(pstEvent.szAlarmTime);
string __szAlarmTime = Encoding.Default.GetString(ar);
}
but __szAlarmTime = \0\0\0\0\0\0\0\0??;\b\0\0\0\0?????qUw?g?\u0001\0\0\0\0"
\0\ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 ??; \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ br />
那么写数据会怎么做
i想要这种类型的数据2018-03-12 16.16.25?
\0\0\0\0\0\0\0\0??;\b\0\0\0\0?????qUw?g?\u0001\0\0\0\0 its not humman readable data.
so what will be do for write Data
i want this type of data 2018-03-12 16.16.25 ?
推荐答案
转换工作的可能性很大 - 但是输入不是你所期望的,所以输出看起来不像是一个可读字符串。我首先看一下你得到pst的位置。 Event.szAlarmTime来自并查看任何文档中的定义。很可能它根本不是人类可读的闹钟时间,而是编码的DateTime开始,重复值和/或结束值,你将需要处理更好的细节以获得人类可读的值。
The chances are that the conversion is working perfectly - but the input is not what you expected, so the output doesn't look like a "readable string". I'd start by looking at where you get the pst.Event.szAlarmTime from and look at the definition in any documentation with that. The chances are that it's not a human readable alarm time at all, but an encoded DateTime start, a repeat value and / or an end value which you will need to process in much better detail to get a human readable value from.
这篇关于将char [32]转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!