By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,703 Members | 1,400 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,703 IT Pros & Developers. It's quick & easy.

How do you delete an unwanted char in a string

P: n/a
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

*** Sent via Developersdex http://www.developersdex.com ***
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi,

Take a look at the strings replace method.

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

s = s.Replace("-"c, "")
Ken
---------------
"Jim Bob" <ns***@cableone.net> wrote in message
news:uy**************@TK2MSFTNGP14.phx.gbl...
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

*** Sent via Developersdex http://www.developersdex.com ***
Nov 21 '05 #2

P: n/a
Jim,

Have a look at these two links
RegexLib
http://www.regexlib.com/Default.aspx

Expresso
http://www.ultrapico.com/Expresso.htm
I hope this helps a little bit?

You can of course do as well a loop through the string and look if the
character is a number and when it is then append it to a stringbuilder.

The last will probably be quicker.

I hope this helps,

Cor
Nov 21 '05 #3

P: n/a
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


Jim Bob wrote:
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

*** Sent via Developersdex http://www.developersdex.com ***

Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.