Solved

Finding an integer number in a string surrounded by spaces

Posted on 2013-05-13
5
258 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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…

740 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