data-conversion

JavaScript: create a string or char from an UTF-8 value

徘徊边缘 提交于 2019-12-11 09:42:43
问题 Same question as this, but with UTF-8 instead of ASCII In JavaScript, how can you get a string representation of a UTF-8 value? e.g. how to turn "c385" into "Å" ? or how to turn "E28093" into "—" (m dash) ? or how to turn "E282AC" into "€" (euro sign) ? My question is NOT a duplicate of Hex2Asc. You can see for yourself: hex2a("E282AC") will transform the string into "â¬" instead of transforming it into "€" (euro sign) !! 回答1: I think this will do what you want: function convertHexToString

How to export Pandoc markdown to Worpress.com compatible PHP Markdown Extra?

♀尐吖头ヾ 提交于 2019-12-11 02:54:32
问题 I have markdown documents in Pandoc's standard markdown format, which i would like to publish on a free wordpress.com blog ("free" implies that i cannot install plugins or modify Wordpress PHP files). Officially, wordpress.com supports the PHP Markdown Extra variant that it converts into HTML, so theoretically i could just use Pandoc to convert my files into this markdown_phpextra format (which Pandoc does flawlessly). However, as described in this SO question i noticed that my paragraphs

Transforming nested objects to an array

折月煮酒 提交于 2019-12-11 02:53:36
问题 I have an object that contains other objects, such as: let foo = { a: { b: {}, c: {} }, d: { e: {} } }; Now I want to transform this into an array of objects, where the keys of the first two levels form a key / value pair, such as: let transformedFoo = [ { outer: 'a', inner: 'b' }, { outer: 'a', inner: 'c' }, { outer: 'd', inner: 'e' } ]; My current approach looks like this: let fooTransformed = []; Object.keys(foo).forEach(function (outerKey) { Object.keys(foo[outerKey]).forEach(function

How to compare dates in javascript with two different format?

雨燕双飞 提交于 2019-12-10 21:42:32
问题 function mainFunc() { dueDate = "30/12/2014"; var firstReminderDate = dueDate; var today = new Date(); var firstDate = convertToDate(firstReminderDate); if (today > firstDate) { //send reminder to A } else { // send reminder to B } } function convertToDate(dateString) { var dateData = dateString.split("/"); var date = new Date(new Date().setFullYear(dateData[0], dateData[1] - 1, dateData[2])); return new Date(date); } I need to compare two dates not the time, and how to remove the time part

Problem convert column values from VARCHAR(n) to DECIMAL

徘徊边缘 提交于 2019-12-10 20:19:11
问题 I have a SQL Server 2000 database with a column of type VARCHAR(255). All the data is either NULL, or numeric data with up to two points of precision (e.g. '11.85'). I tried to run the following T-SQL query but received the error 'Error converting data type varchar to numeric' SELECT CAST([MyColumn] AS DECIMAL) FROM [MyTable]; I tried a more specific cast, which also failed. SELECT CAST([MyColumn] AS DECIMAL(6,2)) FROM [MyTable]; I also tried the following to see if any data is non-numeric,

c++ server htons to java ntohs client conversion

自作多情 提交于 2019-12-10 20:08:51
问题 I am creating a small TFTP client server app where server is developed using c++ and client using java. Here i am sending "block count" value using htons conversion. But i am not able to convert it back to its original value at client. For example if am sending block count ntohs(01) (2 bytes) from server to client. Client is reading in bytes. Value which I am receiving is byte 0 and byte 1. Please if any one can provide a solution. 回答1: I take it you meant that you use ntohs to decode the

convert centimeter to feet and inches and vice versa different output?

∥☆過路亽.° 提交于 2019-12-10 17:29:12
问题 I am using following code to convert centimeters into feet and inches but it doesn't work as expected. + (NSString*)getfeetAndInches:(float)centimeter { float totalHeight = centimeter * 0.032808; float myFeet = (int)totalHeight; //returns 5 feet float myInches = fabsf((totalHeight - myFeet) * 12); NSLog(@"%f",myInches); return [NSString stringWithFormat:@"%d' %0.0f\"",(int)myFeet,roundf(myInches)]; } I'm using the following code to convert feet and inches string into centimeter NSInteger

SAS: Converting character to numeric variable - comma as a decimal separator

烂漫一生 提交于 2019-12-10 16:24:49
问题 I'm trying to use INPUT function, as it is always suggested, but it seems that SAS has some problems with proper interpretation of amounts like: 2,30 1,61 0,00 ...and I end up with missing values. Perhaps it's caused by comma being thousands separator where SAS come from ;) data temp; old = '1,61'; new = input(old, 5.2); run; Why the result of above is new = . ? It seems that I've found some work-around - by replacing comma with a period using TRANWRD before INPUT function is called ( vide

Convert bool array to int32 ,unsigned int and double?

[亡魂溺海] 提交于 2019-12-10 11:58:03
问题 I've bool arrays of sizes : 32, 48, 64 (each boolean represents a bit). how can I convert them to a number with a good performance( int, unsigned int, double48, double64)? for example : bool ar[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1} int num = bitArrayToInt32(ar,32);// num = 65 回答1: O(n): int bitArrayToInt32(bool arr[], int count) { int ret = 0; int tmp; for (int i = 0; i < count; i++) { tmp = arr[i]; ret |= tmp << (count - i - 1); } return ret; } int main() { bool ar[]

Problem encoding wav into ogg vorbis

可紊 提交于 2019-12-08 12:04:25
问题 I have an MFC application. I have audio data stored in wav format. My question is, how can I encode an array of those bytes into an ogg vorbis format? I found an example: http://svn.xiph.org/trunk/vorbis/examples/encoder_example.c and tried to use it in my application. First, I tried to add it to my project and compile. I had to add files included in the above file, so I found them in the libraries libvorbis and libogg. And still I cannot link: Error 4 error LNK2019: unresolved external