473,805 Members | 1,910 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

find number in a string

Hello all,

I have a string for example :

strTest = "a lineof text (60) witha number in it"

I need to extract the number from between the brackets, the postion of
the number in brackets is never the same...

So in the above example i need to extract 60

Anyone help on how to do this the simplest way ?

Thanks

andy

Nov 20 '06 #1
6 2017
"androoo" <an**@northwave s.comwrote in news:1164034942 .891789.106920
@m73g2000cwd.go oglegroups.com:
Hello all,

I have a string for example :

strTest = "a lineof text (60) witha number in it"

I need to extract the number from between the brackets, the postion of
the number in brackets is never the same...

So in the above example i need to extract 60

Anyone help on how to do this the simplest way ?
I would use regular expressions - you can specific the search pattern to
only search for numeric characters... like:

[0-9](1,) which will search for 1 or more numeric characters.

Nov 20 '06 #2
thanks, im a bit new to regular expressions but will have a go

Spam Catcher wrote:
"androoo" <an**@northwave s.comwrote in news:1164034942 .891789.106920
@m73g2000cwd.go oglegroups.com:
Hello all,

I have a string for example :

strTest = "a lineof text (60) witha number in it"

I need to extract the number from between the brackets, the postion of
the number in brackets is never the same...

So in the above example i need to extract 60

Anyone help on how to do this the simplest way ?

I would use regular expressions - you can specific the search pattern to
only search for numeric characters... like:

[0-9](1,) which will search for 1 or more numeric characters.
Nov 21 '06 #3

This can work but it is incredibly weak:

Dim strTest As String = "a lineof text (60) witha number in it"

Dim Results As String() = strTest.Split(N ew Char() {"("c,
")"c}, 3)

If Results.Length = 3 Then
Console.Write(" I found " & Results(1) & vbCrLf)
End If
androoo wrote:
thanks, im a bit new to regular expressions but will have a go

Spam Catcher wrote:
"androoo" <an**@northwave s.comwrote in news:1164034942 .891789.106920
@m73g2000cwd.go oglegroups.com:
Hello all,
>
I have a string for example :
>
strTest = "a lineof text (60) witha number in it"
>
I need to extract the number from between the brackets, the postion of
the number in brackets is never the same...
>
So in the above example i need to extract 60
>
Anyone help on how to do this the simplest way ?
I would use regular expressions - you can specific the search pattern to
only search for numeric characters... like:

[0-9](1,) which will search for 1 or more numeric characters.
Nov 22 '06 #4
thanks for your help :)
I will try it out

FishingScout wrote:
This can work but it is incredibly weak:

Dim strTest As String = "a lineof text (60) witha number in it"

Dim Results As String() = strTest.Split(N ew Char() {"("c,
")"c}, 3)

If Results.Length = 3 Then
Console.Write(" I found " & Results(1) & vbCrLf)
End If
androoo wrote:
thanks, im a bit new to regular expressions but will have a go

Spam Catcher wrote:
"androoo" <an**@northwave s.comwrote in news:1164034942 .891789.106920
@m73g2000cwd.go oglegroups.com:
>
Hello all,

I have a string for example :

strTest = "a lineof text (60) witha number in it"

I need to extract the number from between the brackets, the postion of
the number in brackets is never the same...

So in the above example i need to extract 60

Anyone help on how to do this the simplest way ?
>
I would use regular expressions - you can specific the search pattern to
only search for numeric characters... like:
>
[0-9](1,) which will search for 1 or more numeric characters.
Nov 22 '06 #5
Hey Androo,

Try this code:

'
' Create a regex object
'
dim myRegex as new
System.Text.Reg ularExpressions .Regex("(?<numb er>\d+)")
'
' Collect our input string
'
dim myInputString as string = "a lineof text (60) witha number in it"
'
' Capture our input
'
dim myNumber as string =
myRegex.Match(m yInputString).G roups("number") .Value
'
' Use it as we will
'
Console.WriteLi ne(myNumber)

On 21 Nov 2006 11:47:55 -0800, "androoo" <an**@northwave s.comwrote:
>thanks, im a bit new to regular expressions but will have a go

Spam Catcher wrote:
>"androoo" <an**@northwave s.comwrote in news:1164034942 .891789.106920
@m73g2000cwd.g ooglegroups.com :
Hello all,

I have a string for example :

strTest = "a lineof text (60) witha number in it"

I need to extract the number from between the brackets, the postion of
the number in brackets is never the same...

So in the above example i need to extract 60

Anyone help on how to do this the simplest way ?

I would use regular expressions - you can specific the search pattern to
only search for numeric characters... like:

[0-9](1,) which will search for 1 or more numeric characters.
--

Bits.Bytes.
http://bytes.thinkersroom.com
Nov 22 '06 #6
Androoo,

You should use Rad's solution.
androoo wrote:
thanks for your help :)
I will try it out

FishingScout wrote:
This can work but it is incredibly weak:

Dim strTest As String = "a lineof text (60) witha number in it"

Dim Results As String() = strTest.Split(N ew Char() {"("c,
")"c}, 3)

If Results.Length = 3 Then
Console.Write(" I found " & Results(1) & vbCrLf)
End If
androoo wrote:
thanks, im a bit new to regular expressions but will have a go
>
Spam Catcher wrote:
"androoo" <an**@northwave s.comwrote in news:1164034942 .891789.106920
@m73g2000cwd.go oglegroups.com:

Hello all,
>
I have a string for example :
>
strTest = "a lineof text (60) witha number in it"
>
I need to extract the number from between the brackets, the postion of
the number in brackets is never the same...
>
So in the above example i need to extract 60
>
Anyone help on how to do this the simplest way ?

I would use regular expressions - you can specific the search pattern to
only search for numeric characters... like:

[0-9](1,) which will search for 1 or more numeric characters.
Nov 24 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2151
by: Jaime Wyant | last post by:
Will someone explain this to me? >>> "test".find("") 0 Why is the empty string found at position 0? Thanks! jw
7
3991
by: Chris Thunell | last post by:
I'm looking to find in a long string an instance of 4 numbers in a row, and pull out those numbers. For instance: string = "0104 PBR", i'd like to get the 0104. string="PBR XT 0105 TD", i'd like to get the 0105. The numbers will always be 4 digits together. (I'm using vb.net) Any help would be greatly appreciated! Chris cthunell@pierceassociates.com
19
9592
by: ashmangat | last post by:
Hi! now on the chapter "string-class" My assignment is below Word Counter: Write a function that accepts a pointer to a C-String as an argument and returns the number of words contained in the string. For instance, if the string argument is "Four score and seven years ago" the function should return the number 6. Demonstrate the function in a program that asks the user to input a string and then passes it to the function. The number of...
1
4219
by: vmoreau | last post by:
I have a text and I need to find a Word that are not enclosed in paranthesis. Can it be done with a regex? Is someone could help me? I am not familar with regex... Example looking for WORD: (there is a WORD in ( my string WORD )) and * WORD * to (find WORD) and * WORD * Should give me the to word between star (star ar not part of string)
6
2067
by: Oliver Bleckmann | last post by:
hi there, i tried a lot, but it does not work correctly it is more copied to the substr than expected, should be only a "<tag>" but outputs "<tag>etc" shuld parse a xml file like that: <?xml version="1.0" encoding="iso8859-1"?> <Hotel id="0" version="0"> <Room id=> <number>0</number>
4
3844
blyxx86
by: blyxx86 | last post by:
Hi everyone, I am using some VB code to have a "Notes" table be stored for use on all forms that relates to the specific record in any other table. (I haven't used the terminology in a while, but i believe the FK is the primary key of another table???) I have created a table of all the tables in my database: tblTableList TableID; AutoNumber; PK TableName; String DateAdded: Date/Time
3
1975
by: Karthik01 | last post by:
Hi, i have written a VB script to find a node name in an XML.Now i need to search for that node name in another XML. How can i do it. My XML looks like this - <xml xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema"> - <s:Schema id="RowsetSchema"> - <s:ElementType name="row" content="eltOnly"> - <s:AttributeType...
22
4734
by: Steve Richter | last post by:
Does the .NET framework provide a class which will find the item in the collection with a key which is closest ( greater than or equal, less than or equal ) to the keys of the collection? ex: collection keys are 20, 30, 40, 50, 60, 70, 80 find key which is >= 35. would return the 30 key.
2
6667
by: karinmorena | last post by:
I'm having 4 errors, I'm very new at this and I would appreciate your input. The error I get is: Week5MortgageGUI.java:151:cannot find symbol symbol: method allInterest(double,double,double) Location: class Week5MortgageGUI Week5MortgageLogic allint = logic.allInterest(amount, term, rate); Week5MortgageGUI.java:152:cannot find symbol symbol: method allInterest(double,double,double) Location: class Week5MortgageGUI
0
22483
by: zephyrus360 | last post by:
This is about a technique to find the mod of a very large integer with a normal small integer. I recently encountered this problem when I needed to compute the modulus of a very large number with a normal integer. I needed this in a C++ program running on a 32-bit UNIX platform. The problem was that the number was 28 digits long and no native datatype in c++ could store a number of that size. (Eg: 1088263455689473669888943602 % 380) Not...
0
9716
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
9596
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10359
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...
0
9182
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...
1
7645
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5541
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...
1
4317
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3843
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3007
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.