Click here to Skip to main content
15,901,426 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys/girls,

I have one textbox in what clients will write some text like short message.

And it accepts letters, numbers etc.. and thats what I need.
Now, my problem is I need to take numbers from writtent messages and use is for something else.

possible sc :
string message = "My ticket number is : 1005"

string message = "Ticket 1005 is my ticket number"

string message = "Ticket number 1005 and I want to link it"

and so on.. i tryed few thing but none worked. Can you point me to right direction.

Thank You.

What I have tried:

foreach(char ch in TextBox1.Text)
{
if(!char.IsDigit(ch))
{
TextBox1.Text = "True";
}
{
TextBox1.Text = "False";
}
}
Posted
Updated 31-May-18 21:08pm

It's possible, and probably the easiest way - though it may not seem like it - is to use a Regex:
string message = "My ticket number is : 1005";
int value;
Match m = Regex.Match(message, @"\d+");
if (m.Success)
    {
    value = int.Parse(m.Value);
    Console.WriteLine(value * 2);
    }
The string \d+ is a regular expression for "a sequence of digits".
 
Share this answer
 
Use Regular expresssion like below:

var resultString = Regex.Match(message, @"\d+").Value;

Console.WriteLine(resultString);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900