|
-
Oct 4th, 2000, 03:43 PM
#1
Thread Starter
Junior Member
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!
-
Oct 4th, 2000, 03:47 PM
#2
_______
<?>
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
-
Oct 4th, 2000, 03:49 PM
#3
_______
<?>
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
-
Oct 4th, 2000, 03:49 PM
#4
Fanatic Member
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
-
Oct 4th, 2000, 03:53 PM
#5
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]
-
Oct 4th, 2000, 03:55 PM
#6
Fanatic Member
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
-
Oct 4th, 2000, 04:01 PM
#7
Thread Starter
Junior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|