469,640 Members | 1,560 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,640 developers. It's quick & easy.

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 1817
"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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Jaime Wyant | last post: by
7 posts views Thread by Chris Thunell | last post: by
19 posts views Thread by ashmangat | last post: by
6 posts views Thread by Oliver Bleckmann | last post: by
3 posts views Thread by Karthik01 | last post: by
22 posts views Thread by Steve Richter | last post: by
2 posts views Thread by karinmorena | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.