converter

Python 2.7: How to convert unicode escapes in a string into actual utf-8 characters

笑着哭i 提交于 2019-11-29 05:13:43
I use python 2.7 and I'm receiving a string from a server (not in unicode!). Inside that string I find text with unicode escape sequences. For example like this: <a href = "http://www.mypage.com/\u0441andmoretext">\u00b2<\a> How do I convert those \uxxxx - back to utf-8? The answers I found were either dealing with &# or required eval() which is too slow for my purposes. I need a universal solution for any text containing such sequenes. Edit: <\a> is a typo but I want a tolerance against such typos as well. There should only be reaction to \u The example text is meant in proper python syntax

Convert.ChangeType How to convert from String to Enum

倖福魔咒の 提交于 2019-11-29 05:08:57
问题 public static T Convert<T>(String value) { return (T)Convert.ChangeType(value, typeof(T)); } public enum Category { Empty, Name, City, Country } Category cat=Convert<Category>("1");//Name=1 When I call Convert.ChangeType , the system throws an exception on the impossibility of conversion from String to Category. How to do the conversion? Maybe I need to implement any converter for my type? 回答1: Use Enum.Parse method for this. public static T Convert<T>(String value) { if (typeof(T).IsEnum)

IP Address Converter

瘦欲@ 提交于 2019-11-29 03:56:40
问题 There is IP address: 66.102.13.19, and from this address as that received this address http://1113984275 But how? And how I can make this with the help of bash. For example, this service can do it, but I do not understand the algorithm. 回答1: ip=66.102.13.19 IFS=. read -r a b c d <<< "$ip" printf '%s%d\n' "http://" "$((a * 256 ** 3 + b * 256 ** 2 + c * 256 + d))" By the way, the number in your question doesn't match the IP address. To convert a decimal to an IP: #!/bin/bash dec2ip () { local

convert string to arraylist <Character> in java

三世轮回 提交于 2019-11-29 03:14:46
How to convert a String without separator to an ArrayList<Character> . My String is like this: String str = "abcd..." I know one way of doing this is converting the String to char[] first, and then convert the char [] to ArrayList <Character> . Is there any better way to do this? like converting directly? Considering time and performance, because I am coding with a big database. You need to add it like this. String str = "abcd..."; ArrayList<Character> chars = new ArrayList<Character>(); for (char c : str.toCharArray()) { chars.add(c); } use lambda expression to do this. String big_data = "big

How to convert a String array to a Byte array? (java)

江枫思渺然 提交于 2019-11-28 23:40:08
I have a one dimensional String array that I want to convert into a one dimensional byte array. How do I do this? Does this require ByteBuffer? How can I do this? (The strings can be any length, just want to know how to go about doing such an act. And after you convert it into a byte array how could I convert it back into a String array? -Dan Array to Array you should convert manually with parsing into both sides, but if you have just a String you can String.getBytes() and new String(byte[] data) ; like this public static void main(String[] args) { String[] strings = new String[]{"first",

How to pass specific value to the converter parameter?

陌路散爱 提交于 2019-11-28 23:34:50
问题 I have created a class Person that looks like this: public class Person { public enum GenderType { Female, Male } public string Name { get; set; } public GenderType? Gender { get; set; } } Next, I created data template that is going to present objects of type Person. Here's XAML code: <DataTemplate x:Key="personTemplate" DataType="{x:Type model:Person}"> <StackPanel> <RadioButton Content="Female" IsChecked="{Binding Path=Gender, Converter={StaticResource genderConverter}, ConverterParameter=?

Color operations in less

天涯浪子 提交于 2019-11-28 21:59:17
I'm already using color theme in my website, where, for example I have a standard hex color for link states regular/hover/active. Now I want to use color operations in LESS like color:darken(@base_color, x%); So my question is: If I know my base color and my output color after the 'darken' operation, how do I know what % to give the darken operation to produce my output color? eg: If i'm going from #952262 -> #681744 what would be my %? Maybe there's a site that does these conversions? Hopefully the answer is not 'Trial and error'. Has A Few Challenges and Caveats Normally, people do not use a

Java: How to convert String[] to List or Set [duplicate]

◇◆丶佛笑我妖孽 提交于 2019-11-28 21:20:58
问题 This question already has an answer here: How to convert an Array to a Set in Java 17 answers How to convert String[] (Array) to Collection, like ArrayList or HashSet? 回答1: Arrays.asList() would do the trick here. String[] words = {"ace", "boom", "crew", "dog", "eon"}; List<String> wordList = Arrays.asList(words); For converting to Set, you can do as below Set<T> mySet = new HashSet<T>(Arrays.asList(words)); 回答2: The easiest way would be: String[] myArray = ...; List<String> strs = Arrays

Convert between LocalDate and XMLGregorianCalendar

心不动则不痛 提交于 2019-11-28 20:04:20
What's the best way to convert between LocalDate from Java 8 and XMLGregorianCalendar ? Converting from LocalDate to XMLGregorianCalendar : LocalDate date = LocalDate.now(); GregorianCalendar gcal = GregorianCalendar.from(date.atStartOfDay(ZoneId.systemDefault())); XMLGregorianCalendar xcal = DatatypeFactory.newInstance().newXMLGregorianCalendar(gcal); Converting back is simpler: xcal.toGregorianCalendar().toZonedDateTime().toLocalDate(); The LocalDate stores only year/month/day information. There is no time nor time-zone information in it. The XMLGregorianCalendar stores date (year/month/day)

RGB to HSL conversion

纵饮孤独 提交于 2019-11-28 18:44:13
I'm creating a Color Picker tool and for the HSL slider, I need to be able to convert RGB to HSL. When I searched SO for a way to do the conversion, I found this question HSL to RGB color conversion . While it provides a function to do conversion from RGB to HSL, I see no explanation to what's really going on in the calculation. To understand it better, I've read the HSL and HSV on Wikipedia. Later, I've rewritten the function from the "HSL to RGB color conversion" using the calculations from the "HSL and HSV" page. I'm stuck at the calculation of hue if the R is the max value. See the