see unit tests code in Tests.cs
.
code:
StringEx.Format("{0}", "argument1")
result:
argument1
// only register once
StringEx.RegisterFormatFunc("name", () => "PlayerNameA");
// after register
StringEx.Format("{name}")
result:
PlayerNameA
// only register once
StringEx.RegisterFormatFunc("i18n", (index, parameters) =>
{
// TOOD load text from i18n config
return $"i18n_content_({parameters[index]})";
});
// after register
StringEx.Format("{0:i18n}", 1001)
result:
i18n_content_1001
var formatter1 = new StringFormatter.StringFormatter();
formatter1.RegisterFormatFunc("name", () => "name in context1");
var formatter2 = new StringFormatter.StringFormatter();
formatter2.RegisterFormatFunc("name", () => "name in context2");
// after register
formatter1.Format("{name}");
formatter2.Format("{name}");
result:
name in context1
name in context2