Im trying to input numbers as a string and print them out if a certain number was found.
Lets say the number was “1”. How would I check if the string contained “1” and not every “1” that appears such as “10” “14” etc…
Ive tried variableString.contains(“stringneeded”) but it doesnt check for specifics.
Im using C# btw 
kdubnz
2
Will the string only contain a number ?
string sInput = "12";
int number;
bool result = Int32.TryParse(sInput, out number);
if (result)
Console.WriteLine("number: {0}", number);
//----------------------
Do you only want the first number if there are more than one ?
string inputData = "a11is2for3apple,1shiny231and1.1red";
var data = Regex.Match(inputData, @"\d+").Value;
Console.WriteLine("string data: {0}", data);
//----------------------
Do you want a list of ALL numbers ?
string input = "a11is2for3apple,1shiny231and1.1red";
string[] numbers = Regex.Split(input, @"\D+");
foreach (string value in numbers)
{
if (!string.IsNullOrEmpty(value))
{
int i = int.Parse(value);
Console.WriteLine("Integer: {0}", i);
}
}
//----------------------
Result:
number: 12
string data: 11
Integer: 11
Integer: 2
Integer: 3
Integer: 1
Integer: 231
Integer: 1
Integer: 1