Results 1 to 6 of 6

Thread: take text only

  1. #1

    Thread Starter
    Member
    Join Date
    May 2007
    Posts
    60

    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

  2. #2
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,950

    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.

  3. #3

    Thread Starter
    Member
    Join Date
    May 2007
    Posts
    60

    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 ?

  4. #4
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,950

    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

  5. #5

    Thread Starter
    Member
    Join Date
    May 2007
    Posts
    60

    Re: take text only

    thank you so much ,dear bulldog you are exact
    see you soon

  6. #6
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,950

    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
  •  



Click Here to Expand Forum to Full Width