I am not very familiar with writing and reader files yet, so I’m having a tough time figuring this out.
Using StreamWriter, I’m writing the following to a .text file:
UpgradePointsTotalAmount = 5250
Now I need to retrieve the number only, by first checking if “UpgradePointsTotalAmount” exists, and then returning its value.
How would I do that using StreamReader?
Thanks in advance for your time!
Stephane
karl
2
Try this out:
using UnityEngine;
using System.Collections;
using System.Text.RegularExpressions;
public class regex : MonoBehaviour
{
public string s = "afsdlk 10 sdfalkj 30";
// Update is called once per frame
void Start()
{
string[] numbers = Regex.Split(s, @"\D+");
foreach (string value in numbers)
{
if (!string.IsNullOrEmpty(value))
{
int i = int.Parse(value);
Debug.Log("Number: " + i);
}
}
}
}
I wrote this code by adapting the example from this site: http://www.dotnetperls.com/get-numbers-from-string