convert

AutoMapper convert from multiple sources

匿名 (未验证) 提交于 2019-12-03 02:13:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Let's say I have two model classes: public class People { public string FirstName {get;set;} public string LastName {get;set;} } Also have a class Phone: public class Phone { public string Number {get;set;} } And I want to convert to a PeoplePhoneDto like this: public class PeoplePhoneDto { public string FirstName {get;set;} public string LastName {get;set;} public string PhoneNumber {get;set;} } Let's say in my controller I have: var people = repository.GetPeople(1); var phone = repository.GetPhone(4); // normally, without automapper I

Python - Homework - Converting Any Base to Any Base

匿名 (未验证) 提交于 2019-12-03 02:13:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to make a program to convert a number in any base to another base of the user's choice. The code I have so far goes like this: innitvar = float(raw_input("Please enter a number: ")) basevar = int(raw_input("Please enter the base that your number is in: ")) convertvar = int(raw_input("Please enter the base that you would like to convert to: ")) These are the data that I get from the user. The initial number, its initial base, and the base the user wants to convert to. As I understand it, I need to convert to base 10, and then to

How to convert a double to long without casting?

匿名 (未验证) 提交于 2019-12-03 02:13:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: What is the best way to convert a double to a long without casting? For example: double d = 394.000; long l = (new Double(d)).longValue(); System.out.println("double=" + d + ", long=" + l); 回答1: Assuming you're happy with truncating towards zero, just cast: double d = 1234.56; long x = (long) d; // x = 1234 This will be faster than going via the wrapper classes - and more importantly, it's more readable. Now, if you need rounding other than "always towards zero" you'll need slightly more complicated code. 回答2: ... And here is the rounding

How can I convert a timestamp from yyyy-MM-ddThh:mm:ss:SSSZ format to MM/dd/yyyy hh:mm:ss.SSS format? From ISO8601 to UTC

匿名 (未验证) 提交于 2019-12-03 02:13:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to convert the timestamp 2011-03-10T11:54:30.207Z to 10/03/2011 11:54:30.207. How can I do this? I want to convert ISO8601 format to UTC and then that UTC should be location aware. Please help String str_date="2011-03-10T11:54:30.207Z"; DateFormat formatter ; Date date ; formatter = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss.SSS"); date = (Date)formatter.parse(str_date); System.out.println("output: " +date ); Exception :java.text.ParseException: Unparseable date: "2011-03-10T11:54:30.207Z" 回答1: Firstly, you need to be aware that UTC

Cannot convert lambda expression to type 'string' because it is not a delegate type [duplicate]

匿名 (未验证) 提交于 2019-12-03 02:13:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This question already has an answer here: Entity Framework - Cannot convert lambda expression to type 'string' because it is not a delegate type 13 answers I am using a LINQ lambda expression like so: int Value = 1; qryContent objContentLine; using (Entities db = new Entities()) { objContentLine = (from q in db.qryContents where q.LineID == Value orderby q.RowID descending select q).FirstOrDefault(); } However, I am getting the following error: Cannot convert lambda expression to type 'string' because it is not a delegate type 回答1: I think

Convert string date to timestamp in Python

匿名 (未验证) 提交于 2019-12-03 02:13:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How to convert a string in the format "%d/%m/%Y" to timestamp? "01/12/2011" -> 1322697600 回答1: >>> import time >>> import datetime >>> s = "01/12/2011" >>> time.mktime(datetime.datetime.strptime(s, "%d/%m/%Y").timetuple()) 1322697600.0 回答2: To convert the string into a date object: from datetime import date, datetime date_string = "01/12/2011" date_object = date(*map(int, reversed(date_string.split("/")))) assert date_object == datetime.strptime(date_string, "%d/%m/%Y").date() The way to convert the date object into POSIX timestamp depends

Convert RGB to black OR white

匿名 (未验证) 提交于 2019-12-03 02:13:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How would I take an RGB image in Python and convert it to black OR white? Not grayscale, I want each pixel to be either fully black (0, 0, 0) or fully white (255, 255, 255). Is there any built-in functionality for this in the popular Python image processing libraries? If not, would the best way be just to loop through each pixel, if it's closer to white set it to white, if it's closer to black set it to black? 回答1: Scaling to Black and White Convert to grayscale and then scale to white or black (whichever is closest). Original: Result: Pure

how to convert array values from string to int?

匿名 (未验证) 提交于 2019-12-03 02:12:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: $string = "1,2,3" $ids = explode(',', $string); var_dump($ids); returns array(3) { [0]=> string(1) "1" [1]=> string(1) "2" [2]=> string(1) "3" } I need for the values to be of type int instead of type string. Is there a better way of doing this than looping through the array with a foreach and converting each string to int? 回答1: $integerIDs = array_map('intval', explode(',', $string)); 回答2: This is almost 3 times faster than explode() , array_map() and intval() : $integerIDs = json_decode('[' . $string . ']', true); 回答3: So I was curious

C++/CLI Converting from System::String^ to std::string

匿名 (未验证) 提交于 2019-12-03 02:12:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Can someone please post a simple code that would convert, System::String^ To, C++ std::string I.e., I just want to assign the value of, String^ originalString; To, std::string newString; 回答1: Check out System::Runtime::InteropServices::Marshal::StringToCoTaskMemUni() and its friends. Sorry can't post code now; I don't have VS on this machine to check it compiles before posting. 回答2: Don't roll your own, use these handy (and extensible) wrappers provided by Microsoft. For example: #include System::String^ managed = "test"; std::string

How do you convert an image to black and white in PHP

匿名 (未验证) 提交于 2019-12-03 02:12:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How does one go about converting an image to black and white in PHP? Not just turning it into greyscale but every pixel made black or white? 回答1: Simply round the grayscale color to either black or white. float gray = (r + g + b) / 3 if(gray > 0x7F) return 0xFF; return 0x00; 回答2: Using the php gd library: imagefilter($im, IMG_FILTER_GRAYSCALE); imagefilter($im, IMG_FILTER_CONTRAST, -100); Check the user comments in the link above for more examples. 回答3: You could shell out to imagemagick, assuming your host supports it. What function do you