Cool Visual Basic
 
Main
Frequently Asked Questions
VB Helpdesk
Message Boards
Library
Downloads
View Guestbook
Add to Guestbook
Product Reviews
Bookstore
Links
Newsgroups
Vendors
Affiliates
Cooltech.org

Cool VB FAQ


Text Format

The best Visual Basic FAQ(Frequently Asked Quesitions) file on the internet. Do you have a problem that's got you stumped? Do you have the answer to one? We've done our best to make this the best resources for the questions and the answers. Post a question, or a answer to one, by sending email to VBQA@beadsandbaubles.com.

      Root

            String Manipulation

  • Why is it that Chr$(13) does not insert a new line?

    Compatibility:VB3  VB4  VB5

    In order to insert a new line, use the VB Constant vbCrLf, or use chr$(13) & chr$(10).

     

     

  • How can I compare two strings using wildcards?

    Compatibility:VB3  VB4  VB5

    Say you want to compare the string MyStr to the wildcard string "S*" to see if it begins with "S". Do this:

      ...
      if MyStr like "S*" then ...
      ..
    
    .

     

     

  • How should I format dates so that they look correct in all date and langauge formats?

    Compatibility:VB3  VB4  VB5

    Instead of defining your own format, like this:

    myStr = format$(myDate, "mm:dd:yy")
    
    use the predefined types, like this:
    myStr = format$(myDate, "Short Date")
    

     

     

  • How can I count all occurence of one string within another string?

    Compatibility:VB3  VB4  VB5

    Put this code into a module:

    Public Function sCount(String1 As String, String2 As String) As String
        Dim I As Integer, iCount As Integer
        I = 1
            Do
               If (I > Len(String1)) Then Exit Do
               I = InStr(I, String1, String2, vbTextCompare)
               If I Then
                  iCount = iCount + 1
                  I = I + 2
                  DoEvents
               End If
            Loop While I
        sCount = iCount
    End Function
    

     

     

  • How can I remove all occurences of one string within another string?

    Compatibility:VB3  VB4  VB5

    Put this code into a module:

    Public Sub sRemove(String1 As String, String2 As String)
        Dim I As Integer
        I = 1
            Do
               If (I > Len(String1)) Then Exit Do
               I = InStr(I, String1, String2)
               If I Then
                  String1 = Left$(String1, I - 1) + Mid$(String1, I + Len(String2)+1)
                  I = I + 2
                  DoEvents
               End If
            Loop While I
    End Sub
    

     

     

  • How can I replace all occurences of one string within another string with a third string?

    Compatibility:VB3  VB4  VB5

    Put this code into a module:

    Public Sub sReplace(String1 As String, String2 As String, RepString As String)
    
        Dim I As Integer
        I = 1
            Do
               If (I > Len(String1)) Then Exit Do
               I = InStr(I, String1, String2)
               If I Then
                  String1 = Left$(String1, I - 1) + RepString + Mid$(String1, I + Len(String2)+1 )
                  I = I + 2
                  DoEvents
               End If
            Loop While I
    

     

     

    LinkExchange
    LinkExchange Member Free Home Pages at GeoCities


    Copyright 2000, David J Berube<Form1@aol.com>. All Rights Reserved.