Solved

Finding an integer number in a string surrounded by spaces

Posted on 2013-05-13
5
249 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 74

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 74

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now