Click here to Skip to main content
13,894,165 members
Rate this:
Please Sign up or sign in to vote.
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)
TextBox1.Text = "True";
TextBox1.Text = "False";
Updated 31-May-18 21:08pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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".
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Use Regular expresssion like below:

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


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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web06 | 2.8.190306.1 | Last Updated 1 Jun 2018
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100