How do you delete an unwanted char in a string

  • Thread starter Thread starter Jim Bob
  • Start date Start date
J

Jim Bob

I have a character Data field coming in such as
06-1460-2
40 5000 55 5
50-4-55-6445

I need to strip the dash, blanks or any other non numeric
character from this field and return just the numbers

such as
0614602
405000555
504556445

I need a function in VB.net.

Can this be done?


jwc
 
Hi,

Take a look at the strings replace method.

Dim s As String = "06-1460-2"

s = s.Replace("-"c, "")


Ken
---------------
I have a character Data field coming in such as
06-1460-2
40 5000 55 5
50-4-55-6445

I need to strip the dash, blanks or any other non numeric
character from this field and return just the numbers

such as
0614602
405000555
504556445

I need a function in VB.net.

Can this be done?


jwc
 
this will do un anything u want
Private Function EnchancedSplit(ByVal stringTosplit As String, ByVal
deLimiter() As Char) As String()
Dim Words() As String
Words = stringTosplit.Split(deLimiter)
Dim Filterwords As New ArrayList
Dim word As String
For Each word In Words
If word <> String.Empty Then
Filterwords.Add(word)
End If
Next
Return CType(Filterwords.ToArray(GetType(String)), String())
End Function

add 2 textboxes and button
Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim seperator As Char = TextBox2.Text
Dim words() As String = EnchancedSplit(TextBox2.Text, TextBox3.Text)
Dim word As String
For Each word In words
TextBox1.AppendText(word)
Next
End Sub

textbox2 => u enter

40 5000 55 5

in textbox3 u enter:
-" " etc, u put can all unwanted char
or
-
or
" "
regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top