convert

C# Convert string from UTF-8 to ISO-8859-1 (Latin1) H

匿名 (未验证) 提交于 2019-12-03 02:11:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have googled on this topic and I have looked at every answer, but I still don't get it. Basically I need to convert UTF-8 string to ISO-8859-1 and I do it using following code: Encoding iso = Encoding . GetEncoding ( "ISO-8859-1" ); Encoding utf8 = Encoding . UTF8 ; string msg = iso . GetString ( utf8 . GetBytes ( Message )); My source string is But unfortunately my result string becomes What I'm doing wrong here? 回答1: Use Encoding.Convert to adjust the byte array before attempting to decode it into your destination encoding.

Convert blob URL to normal URL

匿名 (未验证) 提交于 2019-12-03 02:11:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: My page generates a URL like this: "blob:http%3A//localhost%3A8383/568233a1-8b13-48b3-84d5-cca045ae384f" How can I convert it to a normal address? I'm using it as an <img> 's src attribute. 回答1: A URL that was created from a JavaScript Blob can not be converted to a "normal" URL. A blob: URL does not refer to data the exists on the server, it refers to data that your browser currently has in memory, for the current page. It will not be available on other pages, it will not be available in other browsers, and it will not be

Convert a Scala list to a tuple?

匿名 (未验证) 提交于 2019-12-03 02:11:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How can I convert a list with (say) 3 elements into a tuple of size 3? For example, let's say I have val x = List(1, 2, 3) and I want to convert this into (1, 2, 3) . How can I do this? 回答1: You can't do this in a typesafe way. Why? Because in general we can't know the length of a list until runtime. But the "length" of a tuple must be encoded in its type, and hence known at compile time. For example, (1,'a',true) has the type (Int, Char, Boolean) , which is sugar for Tuple3[Int, Char, Boolean] . The reason tuples have this restriction is

How do I convert CamelCase into human-readable names in Java?

匿名 (未验证) 提交于 2019-12-03 02:11:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'd like to write a method that converts CamelCase into a human-readable name. Here's the test case: public void testSplitCamelCase() { assertEquals("lowercase", splitCamelCase("lowercase")); assertEquals("Class", splitCamelCase("Class")); assertEquals("My Class", splitCamelCase("MyClass")); assertEquals("HTML", splitCamelCase("HTML")); assertEquals("PDF Loader", splitCamelCase("PDFLoader")); assertEquals("A String", splitCamelCase("AString")); assertEquals("Simple XML Parser", splitCamelCase("SimpleXMLParser")); assertEquals("GL 11 Version"

Convert Python dict to object?

匿名 (未验证) 提交于 2019-12-03 02:10:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm searching for an elegant way to convert a normal Python dict with some nested dicts to an object. For example: >>> d = {'a': 1, 'b': {'c': 2}, 'd': ["hi", {'foo': "bar"}]} Should be accessible in this way: >>> x = dict2obj(d) >>> x.a 1 >>> x.b.c 2 >>> x.d[1].foo bar I think, this is not possible without recursion, but what would be a nice way to get an objectstyle for dicts? 回答1: Update: In Python 2.6 and onwards, consider whether the namedtuple data structure suits your needs: >>> from collections import namedtuple >>> MyStruct =

TypeError: Can&#039;t convert &#039;int&#039; object to str implicitly

匿名 (未验证) 提交于 2019-12-03 02:10:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to write a text game and I have run into an error in the function I am defining that lets you basically spend your skill points after you make your character. At first, the error stated that I was attempting to subtract a string from an integer in this part of the code: balance - strength . Obviously that was wrong so I fixed it with strength = int(strength) ... but now I am getting this error which I have never seen before(new programmer) and I am stumped on what exactly it is trying to tell me and how I fix it. Here is my code

Convert DOS line endings to Linux line endings in vim

匿名 (未验证) 提交于 2019-12-03 02:10:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: If I open files I created in Windows, the lines all end with ^M . How do I delete these characters all at once? 回答1: dos2unix is a commandline utility that will do this, or :%s/^M//g will if you use Ctrl - v Ctrl - m to input the ^M, or you can :set ff=unix and vim will do it for you. Docs on the 'fileformat' setting are here , and the vim wiki has a comprehensive page on line ending conversions . Alternately, if you move files back and forth a lot, you might not want to convert them, but rather to do :set ff=dos , so vim will know it's a

How to convert HTML to PDF using iTextSharp

匿名 (未验证) 提交于 2019-12-03 02:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I want to convert the below HTML to PDF using iTextSharp but don't know where to start: <style> . headline { font - size : 200 %} </style> <p> This <em> is </em> <span class = "headline" style = " text - decoration : underline ; " > some </span> <strong> sample <em> text </em></strong> <span style = " color : red ; " > !!! </span> </p> 回答1: First, HTML and PDF are not related although they were created around the same time. HTML is intended to convey higher level information such as paragraphs and tables. Although there are methods

ValueError: could not convert string to float: id

匿名 (未验证) 提交于 2019-12-03 02:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm running the following python script: #!/usr/bin/python import os,sys from scipy import stats import numpy as np f=open('data2.txt', 'r').readlines() N=len(f)-1 for i in range(0,N): w=f[i].split() l1=w[1:8] l2=w[8:15] list1=[float(x) for x in l1] list2=[float(x) for x in l2] result=stats.ttest_ind(list1,list2) print result[1] However I got the errors like: ValueError: could not convert string to float: id I'm confused by this. When I try this for only one line in interactive section, instead of for loop using script: >>> from scipy import

How to convert SecureString to System.String?

匿名 (未验证) 提交于 2019-12-03 02:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: All reservations about unsecuring your SecureString by creating a System.String out of it aside , how can it be done? How can I convert an ordinary System.Security.SecureString to System.String? I'm sure many of you who are familiar with SecureString are going to respond that one should never transform a SecureString to an ordinary .NET string because it removes all security protections. I know . But right now my program does everything with ordinary strings anyway, and I'm trying to enhance its security and although I'm going to be using an