473,799 Members | 2,746 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get numeric value from a string

45 New Member
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
1 3453
Frinavale
9,735 Recognized Expert Moderator Expert
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
4149
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 the value. Then, I allowed people to insert data but only with conditions. They can insert data if the value they are trying to insert is smaller than the one in the database. For "unlimited" value, they can insert any value. My problem is.... if...
5
13861
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 check if the string contains more than 3 numeric characters because i must only process the ones with more than 3.
3
1716
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
4239
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", prec, pi ); // 3.1416 The * in "%.*f" says to use the value of the next
4
10818
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
14986
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
2921
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 the wstring contains a numeric value. This is the actual conversion: double fValue = _wtof(strValue.c_str()); if strValue contains some characters (e.g.: 'aaa'), _wtof returns 0, therefore I do not really know that the input was initially...
2
2513
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 statements -- numeric value out of range. The SQL statements should be right. We took the statements and we tried to execute it manually. It works... in our programm sometimes it crashed and we get a Database Exception: CLI0111E Numeric value...
4
24638
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 doing the conversion properly. Please advice: $ cat substr.sql connect to viper @ create table largenum (id integer not null, lval decimal(21,0) not
13
4141
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 only get the numeric part of the string?
0
9687
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10488
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10257
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10237
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10029
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9077
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6808
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.