|
-
May 8th, 2007, 09:06 AM
#1
Thread Starter
Member
take text only
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
-
May 8th, 2007, 09:12 AM
#2
Re: take text only
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.
-
May 8th, 2007, 09:21 AM
#3
Thread Starter
Member
Re: take text only
thank you very much , that what i wa looking for , "it works "
for numbers , in vb.net
how to declare a character ?
-
May 8th, 2007, 09:37 AM
#4
Re: take text only
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
-
May 8th, 2007, 10:22 AM
#5
Thread Starter
Member
Re: take text only
thank you so much ,dear bulldog you are exact
see you soon
-
May 8th, 2007, 10:26 AM
#6
Re: take text only
Glad to help, assumig your problem is fixed please mark the thread as resolved.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|