To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
MSDN Subscribers: Download the VS 2010 Release Candidate
MSDN Subscribers: Download the VS 2010 Release Candidate
Sell Your Code and Make Money?
Creating your own Tetris game using VB.NET
Article :: Improving Software Economics, Part 4 of 7: Top 10 Principles of Iterative Software Management



Go Back   VBForums > Visual Basic > Visual Basic .NET

Reply Post New Thread
 
Thread Tools Search this Thread Display Modes
Old May 8th, 2007, 10:06 AM   #1
saadmechiche
Member
 
Join Date: May 07
Posts: 56
saadmechiche is an unknown quantity at this point (<10)
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
saadmechiche is offline   Reply With Quote
Old May 8th, 2007, 10:12 AM   #2
Bulldog
Frenzied Member
 
Bulldog's Avatar
 
Join Date: Jun 05
Location: South UK
Posts: 1,653
Bulldog is a jewel in the rough (300+)Bulldog is a jewel in the rough (300+)Bulldog is a jewel in the rough (300+)Bulldog is a jewel in the rough (300+)
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.
__________________

  • If my post helped you, please Rate it
  • If your problem is solved please also mark the thread resolved
I use VS2005/8 Standard (unless otherwise stated).
_________________________________________________________________________________
B.Sc(Hons), AUS.P, C.Eng, MIET, MIEEE, MBCS / MCSE+Sec, MCSA+Sec, MCP, A+, Net+, Sec+, MCIWD, CIWP, CIWA
I wrote my very first program in 1975, using machine code on a mechanical Olivetti teletype connected to an 8-bit, 78 instruction, 1MHz, Motorola 6800 multi-user system with 2k of memory. Using Windows, I dont think my situation has improved.
Bulldog is offline   Reply With Quote
Old May 8th, 2007, 10:21 AM   #3
saadmechiche
Member
 
Join Date: May 07
Posts: 56
saadmechiche is an unknown quantity at this point (<10)
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 ?
saadmechiche is offline   Reply With Quote
Old May 8th, 2007, 10:37 AM   #4
Bulldog
Frenzied Member
 
Bulldog's Avatar
 
Join Date: Jun 05
Location: South UK
Posts: 1,653
Bulldog is a jewel in the rough (300+)Bulldog is a jewel in the rough (300+)Bulldog is a jewel in the rough (300+)Bulldog is a jewel in the rough (300+)
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
__________________

  • If my post helped you, please Rate it
  • If your problem is solved please also mark the thread resolved
I use VS2005/8 Standard (unless otherwise stated).
_________________________________________________________________________________
B.Sc(Hons), AUS.P, C.Eng, MIET, MIEEE, MBCS / MCSE+Sec, MCSA+Sec, MCP, A+, Net+, Sec+, MCIWD, CIWP, CIWA
I wrote my very first program in 1975, using machine code on a mechanical Olivetti teletype connected to an 8-bit, 78 instruction, 1MHz, Motorola 6800 multi-user system with 2k of memory. Using Windows, I dont think my situation has improved.
Bulldog is offline   Reply With Quote
Old May 8th, 2007, 11:22 AM   #5
saadmechiche
Member
 
Join Date: May 07
Posts: 56
saadmechiche is an unknown quantity at this point (<10)
Re: take text only

thank you so much ,dear bulldog you are exact
see you soon
saadmechiche is offline   Reply With Quote
Old May 8th, 2007, 11:26 AM   #6
Bulldog
Frenzied Member
 
Bulldog's Avatar
 
Join Date: Jun 05
Location: South UK
Posts: 1,653
Bulldog is a jewel in the rough (300+)Bulldog is a jewel in the rough (300+)Bulldog is a jewel in the rough (300+)Bulldog is a jewel in the rough (300+)
Re: take text only

Glad to help, assumig your problem is fixed please mark the thread as resolved.
__________________

  • If my post helped you, please Rate it
  • If your problem is solved please also mark the thread resolved
I use VS2005/8 Standard (unless otherwise stated).
_________________________________________________________________________________
B.Sc(Hons), AUS.P, C.Eng, MIET, MIEEE, MBCS / MCSE+Sec, MCSA+Sec, MCP, A+, Net+, Sec+, MCIWD, CIWP, CIWA
I wrote my very first program in 1975, using machine code on a mechanical Olivetti teletype connected to an 8-bit, 78 instruction, 1MHz, Motorola 6800 multi-user system with 2k of memory. Using Windows, I dont think my situation has improved.
Bulldog is offline   Reply With Quote
Reply

Go Back   VBForums > Visual Basic > Visual Basic .NET


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 09:54 AM.




To view more projects, click here

Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.