473,388 Members | 1,230 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,388 software developers and data experts.

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 1992
"androoo" <an**@northwaves.comwrote in news:1164034942.891789.106920
@m73g2000cwd.googlegroups.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**@northwaves.comwrote in news:1164034942.891789.106920
@m73g2000cwd.googlegroups.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(New 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**@northwaves.comwrote in news:1164034942.891789.106920
@m73g2000cwd.googlegroups.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(New 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**@northwaves.comwrote in news:1164034942.891789.106920
@m73g2000cwd.googlegroups.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.RegularExpressions.Regex("(?<number>\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(myInputString).Groups("number").Valu e
'
' Use it as we will
'
Console.WriteLine(myNumber)

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

Spam Catcher wrote:
>"androoo" <an**@northwaves.comwrote in news:1164034942.891789.106920
@m73g2000cwd.googlegroups.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(New 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**@northwaves.comwrote in news:1164034942.891789.106920
@m73g2000cwd.googlegroups.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
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
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...
19
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...
1
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:...
6
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...
4
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...
3
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...
22
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:...
2
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)...
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
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
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...

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.