473,395 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to get numeric value from a string

Hi,
I have a StatusStrip and is filled with Year in the format say "June2009 - May2010".
I want to get the years from this string like 2009,2010 from the above string.
Please suggest how can i do this.
I have tried this but not able to further separate June2009.
Please have a look
Expand|Select|Wrap|Line Numbers
  1.  Dim strYearDet As String()
  2.  strYear11, strYear2 As String
  3.  strYearDet = StatusStrip1.Items(0).Text.Split("-")
  4.  strYear11 = strYearDet(0)
  5.  strYear2 = strYearDet(1)
  6.  
Can anyone help of how to get 2009 and 2010 from the string
Oct 18 '11 #1

✓ answered by Frinavale

Use the Regex Class to retrieve the numbers from the string.

For example:
Expand|Select|Wrap|Line Numbers
  1. Dim theString As String = "June2009 - May2010"
  2. Dim numRegEx As New System.Text.RegularExpressions.Regex("[0-9]{4}")
  3. Dim matches As System.Text.RegularExpressions.MatchCollection = numRegEx.Matches(theString)
  4. Dim num1 As Integer
  5. Dim num2 As Integer
  6. If matches.Count = 2 Then
  7.   Integer.TryParse(matches(0).Value, num1)
  8.   Integer.TryParse(matches(1).Value, num2)
  9. End If
-Frinny

1 3269
Frinavale
9,735 Expert Mod 8TB
Use the Regex Class to retrieve the numbers from the string.

For example:
Expand|Select|Wrap|Line Numbers
  1. Dim theString As String = "June2009 - May2010"
  2. Dim numRegEx As New System.Text.RegularExpressions.Regex("[0-9]{4}")
  3. Dim matches As System.Text.RegularExpressions.MatchCollection = numRegEx.Matches(theString)
  4. Dim num1 As Integer
  5. Dim num2 As Integer
  6. If matches.Count = 2 Then
  7.   Integer.TryParse(matches(0).Value, num1)
  8.   Integer.TryParse(matches(1).Value, num2)
  9. End If
-Frinny
Oct 18 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Iona | last post by:
okay.. this should be long.. I made up a table in database with access consists of columns with text type. Some of them I put in data with numeric value and some of them I put in "Unlimited" as...
5
by: ief | last post by:
hi all, i'm trying to check the length of a numeric value in a string. this is what i need to do: I have a string "Mystring (253)" and a string "SecondString (31548745754)" Now i have to...
3
by: eric_caron_31 | last post by:
Here's my problem, I read numeric value and I want to display this value like this : 123 678. Value read : 123678 Value display : 123 678 I want space for separator thanks for your help
2
by: mdeaver2003 | last post by:
I'm trying to output a double using a precision that varies, governed by the value of a precision variable. In C I can do it like this: double pi = 3.14159; int prec = 4; printf( "%.*f",...
4
by: Surek | last post by:
I need to get the numeric value alone in a string which includes special characters and alphabets. eg string: vism/t1-1/1 Should retrieve the first numeric value from the given string.
13
by: nishit.gupta | last post by:
Is their any fuction available in C++ that can determine that a string contains a numeric value. The value cabn be in hex, int, float. i.e. "1256" , "123.566" , "0xffff" Thnx
6
by: frohlinger | last post by:
Hi, I need to perform some numeric calculations on a numeric float value, that is received as wstring. I would like to perform a check before converting the wstring to float, checking that indeed...
2
by: tron_23 | last post by:
hi, we use Toplink (TopLink - 4.6.0 (Build 417) with a DB2 Database 7.2. i know really old versions, but we could change to e newer one ;-) Sometimes we got some problems with update or insert...
4
by: Serman D. | last post by:
I would like to extract the first 6 digits of a numeric value (e.g. the string '123456' out of the numeric 1234567890123456789). I tried a combination of CAST and SUBSTR, but it seems I am not...
13
by: arial | last post by:
Hi all, I need some help from you expert. I need to extract numeric value of a string. for ext: string str = "1234 absc st" or it can be "123 hello world" or "1234567 asp.net" How can i...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.