Showing posts with label special-characters. Show all posts
Showing posts with label special-characters. Show all posts

Tuesday, January 16, 2018

Display a python output with special characters in GUI label unity

Leave a Comment

Am running a python script from unity, and I want the output to be displayed in a GUI label in unity, the output contain special characters like é,ç,... but am getting symbols instead. This is what I tried so far but no luck

using (Process proc = Process.Start (start)) {             using (StreamReader reader = proc.StandardOutput) {                 string result = reader.ReadToEnd ();                 UTF8Encoding utf8 = new UTF8Encoding ();                 byte[] encodedBytes = utf8.GetBytes (result);                 UnityEngine.Debug.Log (result);                 Message1.text = result;              }         } 

result is the output: it should be

('fromaje', 'Fausse:') ('Correction suggérér:','fromage') 

But am getting:

enter image description here

1 Answers

Answers 1

When you create your process use:

    var proc = new Process {     StartInfo = new ProcessStartInfo {         FileName = "python.exe whatever.py",         Arguments = "yourargs",         UseShellExecute = false,         RedirectStandardOutput = true,         CreateNoWindow = true     }  }; 

Then read the string by doing this:

proc.Start(); StringBuilder bldr = new StringBuilder(); while (!proc.StandardOutput.EndOfStream) {     bldr.append(proc.StandardOutput.ReadLine()+"\n"); } 

You can get the full output by doing:

bldr.ToString() 
Read More

Tuesday, March 29, 2016

mysqldump, avoid escape double quotes

Leave a Comment

When I have a field with double quotes, mysqldump put the escape character before. For example:

'My "test"' -> mysqldump generates a file with that field like 'My \"test\"'

The problem is that I'm using that file to import some data into a sqlite database, and SQLite doesn't remove the escape character. So I don't need that mysqldump writes escape characters, can I do that?

3 Answers

Answers 1

I am unsure what language you are using. But the concept would be the same in any programming language.

First declare a variable equal to your sqldump.

var yourVariable = sqldump; 

Then do a string.replace("\\", ""). Then use that 'cleaned' version to import your data with.

Answers 2

Which SQL mode do you use? Look at the mysqldump manual: http://dev.mysql.com/doc/refman/5.7/en/mysqldump.html

--quote-names, -Q

Quote identifiers (such as database, table, and column names) within “`” characters. If the ANSI_QUOTES SQL mode is enabled, identifiers are quoted within “"” characters. This option is enabled by default. It can be disabled with --skip-quote-names, but this option should be given after any option such as --compatible that may enable --quote-names.

--quote-names is enabled by default.

ANSI_QUOTES

Treat “"” as an identifier quote character (like the “`” quote character) and not as a string quote character. You can still use “`” to quote identifiers with this mode enabled. With ANSI_QUOTES enabled, you cannot use double quotation marks to quote literal strings, because it is interpreted as an identifier.

Answers 3

From a google search I found this which is reworking the output of mysqldump so sqlite can use it. Not tested and 5 years old but I think:

  • you may find useful information
  • it may mean other people didn't find a more elegant solution

EDIT:

As per the comments, to answer your question it looks like you don't have a choice but replace \" into ".

Here is a repo with a script which translates mysqldump files into something sqlite can digest. In particular, for your question, you can find this line:

gsub( /\\"/, "\"" ) 
Read More