HI EVERYBODY
i would like to know if there is a function in vb.net that can take a text without spaces or numbers .
ex:
dim p as string
p=inputbox("give a text please")
' the text for example is "hello "
what I want is just "hello"
thank you
SAAD
Printable View
HI EVERYBODY
i would like to know if there is a function in vb.net that can take a text without spaces or numbers .
ex:
dim p as string
p=inputbox("give a text please")
' the text for example is "hello "
what I want is just "hello"
thank you
SAAD
Trim will remove any leading or trailing spaces.
So NewString = MyString.Trim
To remove numbers you would need a small function to loop through the characters and strip any numbers out.
thank you very much , that what i wa looking for , "it works "
for numbers , in vb.net
how to declare a character ?
I think this does what you want.
Code:Option Strict On
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim MyString As String = "This is my 8 text and it 5 has some 10 numbers in it"
MessageBox.Show(StripNumbersAndDoubleSpaces(MyString.Trim))
End Sub
Private Function StripNumbersAndDoubleSpaces(ByVal instring As String) As String
Dim str As String = String.Empty
Dim PreviousCh As Char = Nothing
For Each ch As Char In instring
If Not Char.IsNumber(ch) Then
If ch = " " Then
If Not PreviousCh = " " Then str += ch
Else
str += ch
End If
PreviousCh = ch
End If
Next
Return str
End Function
End Class
thank you so much ,dear bulldog you are exact
see you soon
Glad to help, assumig your problem is fixed please mark the thread as resolved.