简体   繁体   中英

to transcribe a string calling it with the name of another string, is it possible? in c# on unity

I have a string variable called "A" and the internal string is "a000_1" (the numbers of this string can change.) then I have other strings called: "a000_1", "a000_2", "a000_3" etc ... (with each a different text inside) I have to transcribe the variables a001 etc. calling them automatically with the string "A"

so if the text inside the string "A" is, for example, "a000_7" it must transcribe the text inside the variable "a000_7"

ExampleText.SetText(A)

but obviously if I do that transcribes me "a000_7", if we want to go back to the example above, and not the text inside the variable a000_7

I guess you could use a dictionary here:

Dictionary<string, string> dict = new Dictionary<string, string> {
    ["a000_1"] = "test1",
    ["a000_2"] = "test2",
    ["a000_3"] = "test3",
    ["a000_4"] = "test4",
    ["a000_5"] = "test5",
    ["a000_6"] = "test6",
    ["a000_7"] = "test7",
};
String A = "a000_7";
Console.WriteLine(dict[A]);

In this case, you can access one of the strings by name by using A as the key to the dict

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM