Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DmgProb[] regex3(string input = "0[18/6]2[20/5]10[15/4]")
- {
- string lastIndexPattern = @"(?<index>\d+)(\[(\d+)/(\d+)\])$";
- int lastIndex = int.Parse(Regex.Match(input, lastIndexPattern).Groups["index"].Value);
- string pattern = @"(?<index>\d+)\[(?<damage>\d+)/(?<probability>\d+)\]";
- DmgProb[] arr = new DmgProb[lastIndex];
- List<DmgProb> matches = new List<DmgProb>();
- Dictionary<int, DmgProb> indexedDictionary = new Dictionary<int, DmgProb>();
- foreach(Match m in Regex.Matches(input, pattern))
- {
- indexedDictionary.Add(
- int.Parse(m.Groups["index"].Value),
- new DmgProb{
- damage = float.Parse(m.Groups["damage"] .Value),
- probability = float.Parse(m.Groups["probability"].Value)
- }
- );
- }
- DmgProb lastDmgProb = indexedDictionary[0];
- for(int i = 0; i < lastIndex; i++)
- {
- if(!indexedDictionary.ContainsKey(i))
- arr[i] = lastDmgProb;
- else
- arr[i] = lastDmgProb = indexedDictionary[i];
- }
- return arr;
- }
Advertisement
Add Comment
Please, Sign In to add comment