Question about strings

WannaLearnASP

New member
Joined
Oct 4, 2004
Messages
3
Programming Experience
1-3
Folks

I am new to Vb.net programming, I have this problem Try to help me out.

I have few phone numbers like this

8122121223EXT123
2126743Parents

I am trying to write a program to find the Characters in the given string
and if there is a character then cut that string at that point and give me the previous numbers

ie I have to cut the string at "E" and give the number 8122121223 back
similarly I have to cut the string at "P" and give 2126743 back.

For this I am checking like this:

If Not IsNumeric(PhoneNumber ) then

Dim arr() As Char
arr = PhoneNumber.ToCharArray

Dim c As Char
Dim str As String

'I am checking each character if it is a number or an alphabet

For Each c In arr
If Not Asc(c) < Asc("A") Or Asc(c) > Asc("Z") Then

'How do I cut the remaining number??
End If

Next c

end if

I hope I did not confuse, can you give me solution asap.


Thanks
 

Schenz

Well-known member
Joined
Sep 11, 2004
Messages
181
Location
Cincinnati, OH
Programming Experience
5-10
I am doing something similar, because my DB only allows numeric entry for a phone number:

VB.NET:
' Must be sure to remove spaces, and any other non numeric characters
Dim counter As Integer
Dim stringarray(value.Length) As String
Dim newValue As String = ""
Dim member As String

' Place all each character into a string array
For counter = 1 To value.Length
   stringarray(counter) = Mid(value, counter, 1)
Next

' Go through each value and if it is a number add it to the newValue
For Each member In stringarray
   If IsNumeric(member) Then
      newValue += String.Concat(member.ToString)
   End If
Next
 
Top Bottom