Enum ToString via Int (JS)

for (var L in lines)
{
var Done1 : boolean = false;
var S = L.Substring(5).Split(“;”[0]);
ImportedItems.Add(ImportedItems[0]);
var values = S[0].Replace(" “,”“).Split(”, "[0]);
ImportedItems.Name = values[0];
ImportedItems.Desc = values[1];
ImportedItems.Price = float.Parse(values[2]);
Debug.Log("String version of Type: " + values[3]);
/if(values[3] == “Loot”)
{
ImportedItems[x].Type = 1;
}
/
for(var x = 0; x < 10 && !Done1; x++)
{
if(float.Parse(values[3]) == Type[ x ])
{
ImportedItems.Type = float.Parse(values[3]);
Done1 = true;
}
}
if(x == 10 && !Done1)
Debug.LogError(“Error: Item Type fail!”);

I have this piece of code and need to know how to fix the if statement… "Type.x.ToString(“F”)) obiously doesn’t work. So how do i take the x value of the enum, and make it a string? Anyone?
Inside “Type” there is:

enum Type { Loot = 1, Food = 2, Weapon = 3, Hat = 4, Shoulders = 5, Gloves = 6, 
Body = 7, Pants = 8, Boots = 9, Coins = 10, none }

Inside the text asset value is taken out of is the following:

Item: Sword, An old rusty Sword, 15, Weapon;
Item: Axe, An old rusty Axe, 10, Weapon;
Item: Toast, Tasty apple pie, 500, Food;
Item: Battery, Metallica and metal, 5, Loot;

The number values in the enum was a way to possibly fix it by putting a float inside the textasset but i still needed to acesss Type with ‘x’.

Thanks in advance.

-CDK

I believe your question is:

"How can I convert a string to an enum of the same name?

enum MyType { Loot = 1, Food = 2, Weapon = 3, Hat = 4, Shoulders = 5, Gloves = 6, 
Body = 7, Pants = 8, Boots = 9, Coins = 10, none };

MyType fred = ConvertFunction("weapon");

How should I write ConvertFunction?"

In which case just have a big if-else if statement that maps the strings to the enum values.

See Enum.ToString Method (System) | Microsoft Learn and Enum.GetValues Method (System) | Microsoft Learn and Enum.TryParse Method (System) | Microsoft Learn