python程序如下(文件名为Obtain.py):
def test(strinfo):
a = "求助帖:"
b = a + strinfo
return b
C#中的代码如下(这是一个界面程序):
namespace getinfo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
void Obtain_Click(object sender, EventArgs e)
{
var result = "";
var engine = IronPython.Hosting.Python.CreateEngine();
var scope = engine.CreateScope();
var source = engine.CreateScriptSourceFromFile("Obtain.py");
source.Execute(scope);
var test = scope.GetVariable<Func<object, object>>("test");
result = (string)test("please help me!\n");
AppendLine(result);
}
public void AppendLine(string s)
{
if (output.Lines.Count() >= 20)
output.Text = string.Join("\r\n", output.Lines.Skip(1));
output.Text += s;
output.SelectionStart = output.TextLength;
output.Focus();
}
}
}
我想把收到的那个包含中英文的字符串输出到richtextbox上,但是显示的结果一直是乱码?求大神指点。。