Results 1 to 7 of 7

Thread: How to remove some characters and spaces from a title?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2000
    Posts
    19
    I'm creating a CD database program, and I want users to enter a title for their CD's. Then I will create a directory for that title with the same name as the title.

    But directories cannot contain the characters :/\ etc. So how do I strip a title from these characters as well as any spaces?

    Thanks for any help!

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    If you use vb6 you can use the replace function:

    myString = Replace(myString,"'","")
    that removes all ' and replaces them with nothing

    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    VB5
    Code:
    Option Explicit
    Option Compare Text
    
    
    
    'Author of function:  John Percival
    'Origin: http://www.vb-world.net/tips/tip110.html
    'Purpose: A Find-and-Replace function for VB5 users
    'Version: VB5+
    
    'function to do the work
    
    Public Function replaceall(searchstring As String, _
         findstring As String, replacestring As String) As String
    
    Dim curpos As Long
    
    curpos = 1
    
    Do
    
    curpos = InStr(curpos, searchstring, findstring)
    searchstring = Left$(searchstring, curpos - 1) & _
    replacestring & Right$(searchstring, Len(searchstring) _
    - curpos - Len(findstring) + 1)
    
    Loop Until InStr(searchstring, findstring) = 0
    
    replaceall = searchstring
    
    End Function
    
    'call to get the work done
    'x = string to be searched
    'y = what to search for
    'z = what to replace it with
    
    Private Sub Command1_Click()
    
    Dim x As String, y As String, z As String
    
    x = "What in the world are we Searching for here, anyway?"
    y = "Searching for"
    z = "Replacement Value"
    Call replaceall(x, y, z)
    MsgBox x
    
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  4. #4
    Fanatic Member Dim's Avatar
    Join Date
    Jul 2000
    Posts
    620
    If you're using VB6 then you can use the Replace function.
    Code:
    'spaces
    Text1.Text = Replace(Text1.Text, " ", "")
    'colon
    Text1.Text = Replace(Text1.Text, ":", "")
    'slash
    Text1.Text = Replace(Text1.Text, "/", "")
    'and so on
    Gl,
    D!m
    Dim

  5. #5
    Guest
    try this:
    Code:
    Private Declare Function StrSpn Lib "SHLWAPI" Alias _
      "StrSpnW" (ByVal psz as Long, ByVal pszset as Long) as Long
    
    Public Function IsAlphaNumeric(ByVal sString as String) as Boolean
    Dim lPos as Long
    Const ALPHA_NUM as String = "abcdefghijklmnopqrstuvwxyz" & _
      "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
    
      'Returns the first occurrence of nonmatching characters
      lPos = StrSpn(StrPtr(sString), StrPtr(ALPHA))
      ' If the return position is not equal to the length of the
      ' input string, non-alpha chars were found.
      IsAlphaNumeric = (lPos = Len(sString))
    
    End Function
    then you can use the function like this:
    Code:
    If IsAlphaNumeric(myText.text) = False Then
      MsgBox "Sorry. Special Characters Not Allowed."
    End If
    hope this helps.


    [Edited by billyboy on 10-04-2000 at 04:56 PM]

  6. #6
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633
    Code:
    Option Explicit
    
    Sub Main()
      'PURPOSE: Test Data
      Dim str_Data As String
      str_Data = "How are you today?"
    
      'PURPOSE: Illegal Characters
      Dim str_IllegalChar As String
      str_IllegalChar = "\/:*?""<>|"
      
      Dim str_Char As String
      Dim int_X As Integer
      For int_X = 1 To Len(str_Data)
        str_Char = Mid(str_Data, int_X, 1)
        If InStr(1, str_IllegalChar, str_Char) <> 0 Then
          MsgBox str_Char
        End If
      Next
    End Sub
    Chemically Formulated As:
    Dr. Nitro

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Aug 2000
    Posts
    19
    Well, I am using VB6 so the first option worked great.

    Thanks to you all!

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