How can I transform string to UTF-8 in C#?

As you know the string is coming in as Encoding.Default you could simply use: byte[] bytes = Encoding.Default.GetBytes(myString); myString = Encoding.UTF8.GetString(bytes); Another thing you may have to remember: If you are using Console.WriteLine to output some strings, then you should also write Console.OutputEncoding = System.Text.Encoding.UTF8;!!! Or all utf8 strings will be outputed as gbk…

Split a string into words by multiple delimiters [duplicate]

Assuming one of the delimiters is newline, the following reads the line and further splits it by the delimiters. For this example I’ve chosen the delimiters space, apostrophe, and semi-colon. std::stringstream stringStream(inputString); std::string line; while(std::getline(stringStream, line)) { std::size_t prev = 0, pos; while ((pos = line.find_first_of(” ‘;”, prev)) != std::string::npos) { if (pos > prev) … Read more

Python TypeError: not enough arguments for format string

You need to put the format arguments into a tuple (add parentheses): instr = “‘%s’, ‘%s’, ‘%d’, ‘%s’, ‘%s’, ‘%s’, ‘%s'” % (softname, procversion, int(percent), exe, description, company, procurl) What you currently have is equivalent to the following: intstr = (“‘%s’, ‘%s’, ‘%d’, ‘%s’, ‘%s’, ‘%s’, ‘%s'” % softname), procversion, int(percent), exe, description, company, procurl … Read more

Removing numbers from string [closed]

Would this work for your situation? >>> s=”12abcd405″ >>> result=””.join([i for i in s if not i.isdigit()]) >>> result ‘abcd’ This makes use of a list comprehension, and what is happening here is similar to this structure: no_digits = [] # Iterate through the string, adding non-numbers to the no_digits list for i in s: … Read more

Insert string at specified position

$newstr = substr_replace($oldstr, $str_to_insert, $pos, 0); http://php.net/substr_replace In the above snippet, $pos is used in the offset argument of the function. offsetIf offset is non-negative, the replacing will begin at the offset’th offset into string. If offset is negative, the replacing will begin at the offset’th character from the end of string.