Solved

Finding an integer number in a string surrounded by spaces

Posted on 2013-05-13
5
253 Views
Last Modified: 2013-05-16
Hello Experts,

I need a function that returns a true if a string contains an integer.  But it has to be a true number, no alpha numerics.

example string 1: "This is a string with a number: 123456 so that's true?"
example string 2: "This string has alpha-numeric data: B123456D so that's false?"

So essentially an integer surrounded by spaces.

Thanks!
Moe
0
Comment
Question by:mauricerichard
  • 2
  • 2
5 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39162482
Is the answer you received in your previous question not working?
0
 
LVL 42

Assisted Solution

by:sedgwick
sedgwick earned 200 total points
ID: 39162484
bool IsContainsInteger(string value){
foreach(var str in value.Split(' ')){
int tmp;
if(int.TryParse(str, out tmp))
return true;
}
return false;
}
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 300 total points
ID: 39162506
Never mind. I see what you mean now. You can simply add word boundaries to the answer I gave you in the other question:

string number = Regex.Match(source, @"\b\d+\b").Value;

Open in new window

0
 
LVL 1

Author Comment

by:mauricerichard
ID: 39162527
Thanks for the quick reply everyone, I'll try these solutions!
0
 
LVL 1

Author Comment

by:mauricerichard
ID: 39171113
There were both useful to me, thanks!
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
REGEX HELP 11 43
imap mails 1 24
VB.net Move a class from Solution Items to a project 2 23
jquery datatables, asp.net MVC 9 41
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question