[英]C# Xamarin Android string += does not work
So I've been using this piece of code in a non-xamarin project for a month now and it worked fine, transfer it over to the xamarin project and now it refuses to work. 因此,我已经在一个非xamarin项目中使用了这段代码一个月了,它可以正常工作,将其转移到xamarin项目中,现在它拒绝工作。 From troubleshoting I can tell its the " menu = menu + text[num] + " "; " that does not work (it does not add the strings as I want it to, it just leaves the string as "oder ", like it was set as)Also if I do "num - 1" to get the string form the array it works :/ .
从故障排除中,我可以说出它的“ menu = menu + text [num] +“”;“是行不通的(它没有按我的意愿添加字符串,只是将字符串保留为“ oder”,就像这样也被设置为)如果我执行“ num-1”来从数组中获取字符串,它也会起作用:/。 Is this a xamarin bug or is my code bad?
这是Xamarin错误还是我的代码不好?
public string menuEncrypt(string[] input, MainActivity ac)
{
//Stream Reader to String[]
StreamReader mc = new StreamReader(ac.Assets.Open("Menu_Code.txt"));
StreamReader mt = new StreamReader(ac.Assets.Open("Menu_Text.txt"));
string[] code = streamToArry(mc);
string[] text = streamToArry(mt);
//string[] code = File.ReadAllLines(@"JittersApp/Droid/Assets/Menu Code.txt");
//string[] text = File.ReadAllLines(@"JittersApp/Droid/Assets/Menu Text.txt");
int codemax = code.Length;
int current = 0;
int im = input.Length;
string menu = "oder ";
while (true)
{
if (current < codemax)
{
if (current < im)
{
if (text.Contains(input[current]))
{
int num = 0;
while (true)
{
string item = input[current];
if (text[num].Equals(item))
{
menu = menu + text[num] + " ";
break;
}
else
{
num++;
}
}
}
current++;
}
else
{
break;
}
}
else
{
break;
}
}
new AlertDialog.Builder(ac)
.SetMessage(menu)
.Show();
return menu;
}
So I got around this by adding a useless line to both the text files and then added + 1 to the variable num
, here's the code :) 因此,我通过在两个文本文件中添加一条无用的行,然后在变量
num
添加+ 1来解决了这个问题,这是代码:)
public string menuEncrypt(string[] input, MainActivity ac)
{
//Stream Reader to String[]
StreamReader mc = new StreamReader(ac.Assets.Open("Menu_Code.txt"));
StreamReader mt = new StreamReader(ac.Assets.Open("Menu_Text.txt"));
string[] code = streamToArry(mc);
string[] text = streamToArry(mt);
//string[] code = File.ReadAllLines(@"JittersApp/Droid/Assets/Menu Code.txt");
//string[] text = File.ReadAllLines(@"JittersApp/Droid/Assets/Menu Text.txt");
int codemax = code.Length;
int current = 0;
int im = input.Length;
string menu = "oder ";
while (true)
{
if (current < codemax)
{
if (current < im)
{
if (text.Contains(input[current]))
{
int num = 0;
while (true)
{
string item = input[current];
if (text[num + 1].Equals(item))
{
menu = menu + code[num + 1] + " ";
break;
}
else
{
num++;
}
}
}
current++;
}
else
{
break;
}
}
else
{
break;
}
}
new AlertDialog.Builder(ac)
.SetMessage(menu)
.Show();
return menu;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.