Heyyy Guys,
我正在c#中编写一个新程序,其中一个字符串已从资源中读取,(。txt)但是当我将外化字符串设置为表单标题时,它似乎有2行。我相信这是因为字符串的外化,但我有一个命令将删除新行。这是代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;
using System.Threading;
using System.Diagnostics;
namespace Language
{
public class Language_Reader
{
private static CultureInfo ci = Thread.CurrentThread.CurrentCulture;
private static int word_count = 2;
private static string[] string_array;
private static string temp_string;
private static char[] remove_chars = {'\n'};
public static void makeLanguageStrings() {
if((ci.Name == "en-Us") || (ci.Name == "en-AU") || (ci.Name == "en-BZ") || (ci.Name == "en-CA") || (ci.Name == "en-CB") || (ci.Name == "en-IE") || (ci.Name == "en-JM") || (ci.Name == "en-NZ") || (ci.Name == "en-PH") || (ci.Name == "en-ZH") || (ci.Name == "en-TT") || (ci.Name == "en-GB") || (ci.Name == "en-ZW"))
{
Debug.WriteLine("Loading Resource: English");
//Loading resource
temp_string = Minecraft_Texturepack_Reload.Properties.Resources.Englisch;
Debug.WriteLine("Succeed to load resource.");
//splitting up resource into array
Debug.WriteLine("Splitting up upper resource into string[]");
string_array = temp_string.Split(remove_chars);
for(int i = 0; i < word_count; i++) {
string_array[i].Trim(remove_chars);
//setting Language_Strings strings
if (i == 0)
{
Language_Strings.main_form_Text = string_array[i];
}
if(i == 1)
{
Language_Strings.project_menu_item_Text = string_array[i];
}
}
Debug.WriteLine("Succeeded to set strings' texts");
}
if((ci.Name == "de-DE")) {
Debug.WriteLine("Loading Resource: Deutsch");
//Loading resource
temp_string = Minecraft_Texturepack_Reload.Properties.Resources.Deutsch;
Debug.WriteLine("Succeed to load resource.");
//splitting up resource into array
Debug.WriteLine("Splitting up upper resource into string[]");
string_array = temp_string.Split(remove_chars);
for (int i = 0; i < word_count; i++)
{
string_array[i].Trim(Environment.NewLine.ToCharArray());
//setting Language_Strings strings
if (i == 0)
{
Language_Strings.main_form_Text = string_array[i];
}
if (i == 1)
{
Language_Strings.project_menu_item_Text = string_array[i];
}
}
Debug.WriteLine("Succeeded to set strings' texts");
}
}
}
}
我无法理解为什么还有一条新线。请帮助!
答案 0 :(得分:1)
如何而不是这一行:
Debug.WriteLine("Succeed to load resource.");
//splitting up resource into array
Debug.WriteLine("Splitting up upper resource into string[]");
string_array = temp_string.Split(remove_chars);
for(int i = 0; i < word_count; i++) {
string_array[i].Trim(remove_chars);
//setting Language_Strings strings
if (i == 0)
{
Language_Strings.main_form_Text = string_array[i];
}
if(i == 1)
{
Language_Strings.project_menu_item_Text = string_array[i];
}
}
Debug.WriteLine("Succeeded to set strings' texts");
就是这样:
function saveimage($name, $image) //this should work :)
删除代码:
$var = 5;
function showvar()
{
echo $GLOBALS['var'];
}
showvar(); //5 will be displayed
Deutsch(德国)的变化相同。
然后我建议重构注入一个语言处理程序,但这只是我挑剔的自我:)
答案 1 :(得分:0)
重构您的代码。不确定为什么使用临时字符串或为什么使用循环来获得0
和1
的索引,当它始终相同时。
这应该删除任何新的行字符。如果这不起作用,请告诉我。
public static void makeLanguageStrings()
{
switch (ci.Name)
{
case "en-Us":
case "en-AU":
case "en-BZ":
case "en-CA":
case "en-CB":
case "en-IE":
case "en-JM":
case "en-NZ":
case "en-PH":
case "en-ZH":
case "en-TT":
case "en-GB":
case "en-ZW":
string_array = Minecraft_Texturepack_Reload.Properties.Resources.Englisch.Split(Environment.NewLine).Replace(Environment.NewLine, string.Empty);
break;
case "de-DE":
string_array = Minecraft_Texturepack_Reload.Properties.Resources.Deutsch.Split(Environment.NewLine).Replace(Environment.NewLine, string.Empty);
break;
}
Language_Strings.main_form_Text = string_array[0];
Language_Strings.project_menu_item_Text = string_array[1];
}