Checking strings for letters


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: Checking strings for letters

  1. #1
    Join Date
    Nov 2004
    Location
    UK
    Posts
    185

    Checking strings for letters

    Hi all,

    I have a String : 2134 CC,

    After i read the string, the problem i am trying to slove is how to check the string for any letters, i.e. CC, and if any letters are found, delete them and simply display the numbers i.e. 2134.

    Any thoughs or comments would be appreciated
    Thankyou

  2. #2
    Join Date
    Aug 2004
    Location
    Dublin, Ireland
    Posts
    63
    For any string of text or just the string as formatted above?
    VBForums.com & DevX.com Super Moderator
    Microsoft MVP : Visual Developer - Visual Basic
    My Website

  3. #3
    Join Date
    Sep 2004
    Location
    Lahore
    Posts
    29
    Try the following Code:

    Code:
    Private Sub Command1_Click()
    Dim myStr As String
    myStr = "1234 CC"
    MsgBox Replace(myStr, "CC", "")
    End Sub

  4. #4
    Join Date
    Feb 2004
    Location
    Sydney, Australia
    Posts
    498
    Or for something more widely applicable ....and assuming the appropriate dim's

    Code:
    MyNewStr=""
    for i = 1 to len(MyStr)
       select case mid$(MyStr,i,1)
          case 0 to 9
             MyNewStr=MyNewStr & mid$(MyStr,i,1)
       end select
    next
    at the end of which, MyNewStr will only contain the digits 0 - 9
    Last edited by gupex; 04-07-2005 at 08:09 AM.

  5. #5
    Join Date
    Aug 2004
    Location
    Dublin, Ireland
    Posts
    63
    Gupex; Brilliant idea!
    VBForums.com & DevX.com Super Moderator
    Microsoft MVP : Visual Developer - Visual Basic
    My Website

  6. #6
    Join Date
    Nov 2004
    Location
    UK
    Posts
    185
    Thanks All,
    Thankyou

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center