Is it possible to do replace with a value from a hashtable when using Regex replace, depending on the string that Regex finds? I don’t really know how to explain it good, so here’s my code:
string data_location;
static Hashtable main;
void Start ()
{
// Start with importing language files
main = new Hashtable ();
data_location = Application.dataPath + "/data/language/EN/";
StreamReader main_file = new StreamReader (data_location + "main.txt");
string main_language = main_file.ReadToEnd ();
string[] main_language_lines = main_language.Split ('
');
foreach (string line in main_language_lines)
{
// Save every line
if (line != "")
{
// Add the strings to the hashtable after processing them
string pattern = "{([A-z0-9_]+)}";
string[] line_content = line.Split ('|');
main.Add (line_content[0], Regex.Replace (line_content[1].Replace ("\
“, "
“), pattern, (string) main[”$1”]));
}
}
}
And here’s the content of the file being imported:
GAME_NAME|Derpflerpia
VERSION|{GAME_NAME} PreAlpha v0.1
WELCOME|Welcome to {GAME_NAME}!
WELCOME_TEXT|{GAME_NAME} is still a WIP. Expect many derps and stoff.
Controls:
W - Move forward
A - Move left
S - Move backwards
D - Move right
Q - Show current quests
E - Teleport to the cave
I - Open inventory
P - Pause
Esc - Close game
Enter - Close this window
BACKPACK|Backpack
PAUSED|Paused
QUESTS|Quests
The problem lies in this line: main.Add (line_content[0], Regex.Replace (line_content[1].Replace ("\ ", " "), pattern, (string) main["$1"]));
If I replace it to this it works: main.Add (line_content[0], Regex.Replace (line_content[1].Replace ("\ ", " "), pattern, (string) main["GAME_NAME"]));
But then it will not work in future cases with other strings, so any suggestions how I should do?
Sorry about bad explanations