Hi, I’m trying to figure out how to get the 1 out of “player_skilldata_Standard Weapons=1;” (Value example)
How do I go about doing this? Perhaps I could use “=” as a start and “;” as an end, but how?
I’m close to creating a saving/loading system with serialized values, and I just need to figure out how to load the values back into the game.
You can do it using the method below. It is taken from this question on Stack Overflow: [How do I extract text that lies between parentheses][1]
public string GetNestedString(string str, char start, char end)
{
int s = -1;
int i = -1;
while (++i < str.Length)
if (str *== start)*
{ s = i; break; } int e = -1; while(++i < str.Length) if (str == end) { e = i; break; } if (e > s) return str.Substring(s + 1, e - s - 1); return null; } When you call the above method just pass argument parameters as below: string value = GetNestedString(“player_skilldata_Standard Weapons=1;”, ‘=’, ‘;’); This will return a string representation of “1”, which is the desired value which you can then convert to an integer using: int weaponValue = Int32.Parse(value); You can also use Int32.TryParse instead of Int32.Parse to avoid being thrown an exception.
_*[1]: c# - How do I extract text that lies between parentheses (round brackets)? - Stack Overflow