Find A Int In A String(C#)

I Am Working On A Highscore System, That Takes Player Data, And Stores It In A Text File. I Want To Find The Int(In This Case Its The Gold) In The String, And Then Sort The Sores From Greatest To Least. I Know How To Sort Them, But I Dont Know How To Find An Int In The String. This Is What The Text File Writes -

ScorebardShtuff = PauseMenu.NameString+"---"+WhatShouldKillSay+CombatSystemScurge.WaitNow+"---"+CombatSystemScurge.Gold+" Gold" + " 


Anyone Have Any Ideas? Thanks In Advance,


If the format of the string is always the same, this maybe can help you:

string ScorebardShtuff = PauseMenu.NameString + "---" + WhatShouldKillSay + CombatSystemScurge.WaitNow + "---" + "54565646544" + " Gold" + " 

string p = ScorebardShtuff.Split(new string { “—” }, StringSplitOptions.None);

int gold = Convert.ToInt32(p[2].Substring(0, p[2].IndexOf(' ')));

Important: Variables cant have a “—” or it could bug.

In “gold” now you should have the integer

A regular expression would be better if your string doesn’t have the same format all the time.

using System.Text.RegularExpressions;

protected Regex goldFinder = new Regex(@"(\d+) Gold"); //This instructs the regex to search for a series of 0-9 digits followed by a blank and the the Gold word, and keep the digits.

    // Inside the method where you want to capture the value

    var text = "daslkd asdlk ajsdlkasdj 123123 Gold asdñl 123"; // Replace this with your actual text variable ScorebardShtuff
    var matches = goldFinder.Matches(text);
    var amountText = matches[0].Groups[1].Value;
    int amount = int.Parse(amountText); // In this example, after this line runs, the amount variable holds the 123123 int value.