Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Finding an integer number in a string surrounded by spaces

Posted on 2013-05-13
5
Medium Priority
?
282 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:Meir Rivkin
Meir Rivkin earned 800 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 1200 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
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…
Suggested Courses

783 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