data-conversion

How to convert string to null-terminated one?

时光怂恿深爱的人放手 提交于 2019-12-08 01:30:24
问题 How to convert a simple string to a null-terminated one? Example: Example string: "Test message" Here are the bytes: 54 65 73 74 20 6D 65 73 73 61 67 65 I need string with bytes like follows: 54 00 65 00 73 00 74 00 20 00 6D 00 65 00 73 00 73 00 61 00 67 00 65 00 00 I could use loops, but will be too ugly code. How can I make this conversion by native methods? 回答1: It looks like you want a null-terminated Unicode string. If the string is stored in a variable str , this should work: var bytes

Transform a Series in a dataframe (of pandas/Python) where the columns are the levels of the Series

社会主义新天地 提交于 2019-12-07 22:25:54
问题 I'm working with pandas and I used the groupby: group = df_crimes_query.groupby(["CrimeDateTime", "WeaponFactor"]).size() group.head(20) CrimeDateTime WeaponFactor 2016-01-01 FIREARM 11 HANDS 26 KNIFE 3 OTHER 11 UNDEFINED 102 2016-01-02 FIREARM 10 HANDS 21 KNIFE 8 OTHER 6 UNDEFINED 68 2016-01-03 FIREARM 12 HANDS 13 KNIFE 6 OTHER 5 UNDEFINED 73 2016-01-04 FIREARM 11 HANDS 10 KNIFE 1 OTHER 3 UNDEFINED 84 dtype: int64 The type of it is a Series: type(group) pandas.core.series.Series I would like

Split function for long text fails with VALUE! error

喜你入骨 提交于 2019-12-07 10:03:12
问题 I am using a function that i saw here on Stackoverflow: Function EXTRACTELEMENT(Txt, n, Separator) As String EXTRACTELEMENT = Split(Application.Trim(Txt), Separator)(n - 1) End Function It was spliting an array of data, like this: sRN LMDscandata sRA LMDscandata 1 1 F97BBF 0 0 6D2A 6D2D 71F5A0FA 71F5FD85 0 0 7 0 0 1388 168 0 1 DIST1 3F800000 00000000 D9490 1388 5 6E2 6DC 6E3 6ED 6E1 0 0 0 0 0 0 But when i tried to increase the amount of data: sRN LMDscandata sRA LMDscandata 1 1 F97BBF 0 0

Date and time conversion

别等时光非礼了梦想. 提交于 2019-12-06 15:51:31
问题 I am working on a news app and I get the date and time from the json response in this pattern (2017-09-23T14:22:28Z) . How can I convert this date and time into something like that (5 seconds ago, 10 minutes ago, 3 hours ago, etc)? And after 24 hours past, it should then display the normal date of that particular news headline (2017-09-23). 回答1: You can use this code which I have implemented in my chatting app. public class Utils { private static final int SECOND_MILLIS = 1000; private static

How to convert string to null-terminated one?

空扰寡人 提交于 2019-12-06 13:44:23
How to convert a simple string to a null-terminated one? Example: Example string: "Test message" Here are the bytes: 54 65 73 74 20 6D 65 73 73 61 67 65 I need string with bytes like follows: 54 00 65 00 73 00 74 00 20 00 6D 00 65 00 73 00 73 00 61 00 67 00 65 00 00 I could use loops, but will be too ugly code. How can I make this conversion by native methods? It looks like you want a null-terminated Unicode string. If the string is stored in a variable str , this should work: var bytes = System.Text.Encoding.Unicode.GetBytes(str + "\0"); ( See it run .) Note that the resulting array will have

Converting XML with namespaces to CSV using powershell

时光怂恿深爱的人放手 提交于 2019-12-06 09:21:26
I have this XML file: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ns3:BOX xmlns="urn:loc.gov:item" xmlns:ns2="urn:loc.gov:box" xmlns:ns3="http://www.example.com/inverter" xmlns:ns4="urn:loc.gov:xyz"> <ns3:Item> <Description>ITEM1</Description> <PackSizeNumeric>6</PackSizeNumeric> <ns2:BuyersItemIdentification> <ID>75847589</ID> </ns2:BuyersItemIdentification> <ns2:CommodityClassification> <CommodityCode>856952</CommodityCode> </ns2:CommodityClassification> <ns2:AdditionalItemProperty> <Name>Weight</Name> <Value>0</Value> </ns2:AdditionalItemProperty> <ns2:AdditionalItemProperty>

Transform a Series in a dataframe (of pandas/Python) where the columns are the levels of the Series

ぐ巨炮叔叔 提交于 2019-12-06 07:56:01
I'm working with pandas and I used the groupby: group = df_crimes_query.groupby(["CrimeDateTime", "WeaponFactor"]).size() group.head(20) CrimeDateTime WeaponFactor 2016-01-01 FIREARM 11 HANDS 26 KNIFE 3 OTHER 11 UNDEFINED 102 2016-01-02 FIREARM 10 HANDS 21 KNIFE 8 OTHER 6 UNDEFINED 68 2016-01-03 FIREARM 12 HANDS 13 KNIFE 6 OTHER 5 UNDEFINED 73 2016-01-04 FIREARM 11 HANDS 10 KNIFE 1 OTHER 3 UNDEFINED 84 dtype: int64 The type of it is a Series: type(group) pandas.core.series.Series I would like a dataframe about like this: CrimeDateTime FIREARM HANDS KNIFE OTHER UNDEFINED 2016-01-01 11 26 3 11

Is it safe to encode and decode in c#?

こ雲淡風輕ζ 提交于 2019-12-06 06:51:34
问题 In c# I can encode binary data by Encoding.UTF8.GetString() and later convert it back by binary = Encoding.UTF8.GetBytes() . I expect that the result should be my original binary data in any case - no exception. But is it true in any case? Or does it depend on the specific behaviour of the UTF8 character set? Or should I better use Encoding.ASCII.GetString() and Encoding.ASCII.GetBytes() ? If anybody knows what Encoding exactly does (how it treats special characters or special bytes) then,

Receive UDP packet datagrams in PHP

安稳与你 提交于 2019-12-06 05:18:47
问题 I am working in php to build a listening server for a GPS tracking system. The GPS sends data through UDP packets, which I can display by running the below script. However the actual data comes out in symbols so I am guessing I am missing a conversion //Reduce errors error_reporting(~E_WARNING); //Create a UDP socket if(!($sock = socket_create(AF_INET, SOCK_DGRAM, 0))) { $errorcode = socket_last_error(); $errormsg = socket_strerror($errorcode); die("Couldn't create socket: [$errorcode]

How to output IEEE-754 format integer as a float

烈酒焚心 提交于 2019-12-06 04:52:52
问题 I have a unsigned long integer value which represents a float using IEEE-754 format. What is the quickest way of printing it out as a float in C++? I know one way, but am wondering if there is a convenient utility in C++ that would be better. Example of the way that I know is: union { unsigned long ul; float f; } u; u.ul = 1084227584; // in HEX, this is 0x40A00000 cout << "float value is: " << u.f << endl; (This prints out "float value is: 5" ) 回答1: The union method you suggested is the usual