format phone number

villson7

Member
Joined
Dec 14, 2006
Messages
15
Programming Experience
Beginner
Greeting everyone, i have develop a program that will allow user key in the phone number according to these format: ########## where first two digit represent country code and the remain are the mobile number or phone number.

Q1: can i make the program automactically change the format phone number to ########## whenever which user has entered different format. example when user key in (65) 91234567 , 65-91234567 0r 65 91234567 , it will change it to 6591234567.

Q2: can the program build to support many phone numbers when user key in over 2 phone numbers in different format, it will still change to original form.
example all numbers in the line which contain 65-91234567, (65)97654321, 65 93214567, 65976 51234 to 6591234567, 6597654321, 6593214567 and 6597651234.

Q3: can i also counting how many numbers that user has key in?
example ,6591234567,,6597654321, 6593214567, consider count as 3 numbers
 
You can explore on the regular expression and this is just an example:

VB.NET:
[SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] test [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = "65-91234567, (65)97654321, 65 93214567, 65976 51234 "
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] result [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2].Empty
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] a [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Text.RegularExpressions.Regex = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] System.Text.RegularExpressions.Regex("")
result = a.Replace(test, "[\s()-]", "")
[/SIZE][SIZE=2]MessageBox.Show(result)
[/SIZE]
 
thanks a lot lingsn, anyway can u solved my third question that is counting how many numbers that user has key in?

i m also want to know how do i count the total recipient when a list of phone number show in multiline textbox which display as (12345678, 45678666,23457890) and count as 3 recipients and (,,,,,,12345678,,,,234567890,,45678666) still count as 3 recipients.
 
There are a few ways, 1 ways is use the split to count, and the other way is use the indexof. Example of split

VB.NET:
[SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] test [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = "65-91234567, (65)97654321, 65 93214567, 65976 51234 "
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] result [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2].Empty
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] a [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Text.RegularExpressions.Regex = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] System.Text.RegularExpressions.Regex("\d+,")
result = a.Replace(test, "[\s()-]", "")
[/SIZE][SIZE=2][COLOR=#008000]'result = a.Replace(test, "", "")
[/COLOR][/SIZE][SIZE=2]MessageBox.Show(result.Split(","c).Length)
[/SIZE]
 
I have use this code to get my phone number:

Dim myString As String = "10,234,345,,,567,34"
Dim delimStr As String = ","
Dim delimiter As Char() = delimStr.ToCharArray()
Dim str As String() = Split(myString, delimiter)
Dim i As Integer


For i = 0 To UBound(str)
MsgBox(str(i))
Next

The result for the code showing a array number which will look like:
10
234
354


567
34

Can i have my code modify so that the result will directly show:
10
234
354
567
34
 
VB.NET:
[SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] myString [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = "10,234,345,,,567,34"
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] delimStr [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = ","
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] delimiter [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Char[/COLOR][/SIZE][SIZE=2]() = delimStr.ToCharArray()
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] str [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2]() = Split(myString, delimiter)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] aStr [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Each[/COLOR][/SIZE][SIZE=2] aStr [/SIZE][SIZE=2][COLOR=#0000ff]In[/COLOR][/SIZE][SIZE=2] str
[/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] aStr.Trim <> [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2].Empty [/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE][SIZE=2] MsgBox(str)
[/SIZE][SIZE=2][COLOR=#0000ff]Next
[/COLOR][/SIZE]
 
Thanks for your help again,lingsn somehow when i compile the code, the message below show:
An unhandled exception of type 'System.ArgumentException' occurred in microsoft.visualbasic.dll

Additional information: Argument 'Prompt' cannot be converted to type 'String'.

Any Suggestion?
 
My mistake and this is the correction code:

VB.NET:
[SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] myString [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = "10,234,345,,,567,34"
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] delimStr [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = ","
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] delimiter [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Char[/COLOR][/SIZE][SIZE=2]() = delimStr.ToCharArray()
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] str [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2]() = Split(myString, delimiter)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] aStr [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Each[/COLOR][/SIZE][SIZE=2] aStr [/SIZE][SIZE=2][COLOR=#0000ff]In[/COLOR][/SIZE][SIZE=2] str
[/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] aStr.Trim <> [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2].Empty [/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE][SIZE=2] MsgBox(aStr)
[/SIZE][SIZE=2][COLOR=#0000ff]Next
[/COLOR][/SIZE]
 
thanks a lot for your help, anyway how can i include the remove duplicate number function in your code, example: the string which contain:"10,,11,34,56,,78,99,11,35,11" will display as:
10
11
34
56
78
99
35

which has remove two duplicate number 11. Can it be done?
 
May be used this function to remove array

VB.NET:
[IMG]http://www.xmlfox.com/images/spacer.gif[/IMG]' This function removes duplicate elements from a ReceivedArray().
[IMG]http://www.xmlfox.com/images/spacer.gif[/IMG]' The function does not actually remove the elements. The resulting array
[IMG]http://www.xmlfox.com/images/spacer.gif[/IMG]' will have a less than or equal number of elements than the original array.
[IMG]http://www.xmlfox.com/images/spacer.gif[/IMG]' The final ReturnedArray() will be returned.
[IMG]http://www.xmlfox.com/images/spacer.gif[/IMG]Private Function DeleteDoubleElement(ByRef ReceivedArray()) As String()
[IMG]http://www.xmlfox.com/images/spacer.gif[/IMG] Dim ReturnedArray() As String
[IMG]http://www.xmlfox.com/images/spacer.gif[/IMG] Dim col As New Scripting.Dictionary
[IMG]http://www.xmlfox.com/images/spacer.gif[/IMG] For i = 0 To ReceivedArray.Length - 1
[IMG]http://www.xmlfox.com/images/spacer.gif[/IMG] If Not col.Exists(CStr(ReceivedArray(i))) Then col.Add(CStr(ReceivedArray(i)), 1)
[IMG]http://www.xmlfox.com/images/spacer.gif[/IMG] Next

[IMG]http://www.xmlfox.com/images/spacer.gif[/IMG] ReDim ReturnedArray(col.Count - 1)
[IMG]http://www.xmlfox.com/images/spacer.gif[/IMG] For i = 0 To col.Count - 1
[IMG]http://www.xmlfox.com/images/spacer.gif[/IMG] ReturnedArray(i) = col.Keys(i)
[IMG]http://www.xmlfox.com/images/spacer.gif[/IMG] Next

[IMG]http://www.xmlfox.com/images/spacer.gif[/IMG] col = Nothing
[IMG]http://www.xmlfox.com/images/spacer.gif[/IMG] Return ReturnedArray
[IMG]http://www.xmlfox.com/images/spacer.gif[/IMG]End Function
 
i have include your function in the code :
Dim myString AsString = "10,234,345,,,567,34"
Dim delimStr AsString = ","
Dim delimiter AsChar() = delimStr.ToCharArray()
Dim str AsString() = Split(myString, delimiter)
Dim aStr AsString
ForEach aStr In str
If aStr.Trim <> String.Empty Then
MsgBox(aStr)
DeleteDoubleElement(str)
End If
Next

somehow error show:
An unhandled exception of type 'System.MissingMemberException' occurred in microsoft.visualbasic.dll

Additional information: Public member 'Keys' on type 'IDictionary' not found.

How can improve the code?
 
i have include your function in the code :
Dim myString AsString = "10,234,345,,,567,34"
Dim delimStr AsString = ","
Dim delimiter AsChar() = delimStr.ToCharArray()
Dim str AsString() = Split(myString, delimiter)
Dim aStr AsString
ForEach aStr In str
If aStr.Trim <> String.Empty Then
MsgBox(aStr)
DeleteDoubleElement(str)
End If
Next

somehow error show:
An unhandled exception of type 'System.MissingMemberException' occurred in microsoft.visualbasic.dll

Additional information: Public member 'Keys' on type 'IDictionary' not found.

How can improve the code?
 
I have solve the probelm here is the final code, thanks alot for ur help!

Dim myString AsString = "10,234,345,,,567,34,10,10"
Dim delimStr AsString = ","
Dim delimiter AsChar() = delimStr.ToCharArray()
Dim str AsString() = Split(myString, delimiter)
Dim aStr AsString
str=DeleteDoubleElement(str)
ForEach aStr In str
If aStr.Trim <> String.Empty Then MsgBox(aStr)
Next
:D:)
 
Aiya i have little problem here...when the string contain alphanumeric string example: "12345,,,,abikl:8900,,^&8999,,675,,12345" ,how can i split and remove duplicate number and show the final result as "12345,675"?
 
Back
Top