I came up with this function while trying to validate a filename for a script. The function will take a string and a list of characters to look for and will return true if the string contains one or more of those characters. An example would be looking for \/:*?"<>[]| as these characters should not appear in a filename, so if they exist the filename is not valid. You would call it in the following way:
checkForSpecialChar(newFilename, "\/:*?""<>[]|")
You may notice that there are two " next to each other, because strings are surrounded by " you have to use a " before a " to insert the " in the list, if not the string would close after the ? and you would receive an error.
Not for more advanced users you could also use the regexp to perform something similar.
Function checkForSpecialChar(temp_string As String, temp_list As String) As Boolean
Dim strLen As Integer
Dim tempChar As String
Dim i As Integer
Dim pos As Integer
checkForSpecialChar = FALSE
strlen = Len(temp_list)
For i = 1 To strLen
tempChar = Mid(temp_list, i, 1)
pos = InStr(1, temp_string, tempChar)
If pos > 0 Then
checkForSpecialChar = TRUE
End If
Next i
End Function
Comments
egonzaleze
Fri, 08/26/2016 - 16:21
Permalink
Reusing and improving this script
Hello. I'm trying to get into programming in ideascript, but I'm not exactly a skilled programmer. I used to use "replace" instruction in VB6 in order to change a character for another. So I got 2 question I'll really appreciate you answer to me:
a. Does ideascript allows an identification of regex like '\r\n'?
b. How can I code the replacement of \t,\r\n for ',' ?
Thank you very much!
Brian Element
Mon, 08/29/2016 - 08:02
Permalink
Hi Elías and welcome to the
Hi Elías and welcome to the site.
When I do replacements I use the ASCII codes for the replacement. Such as chr(11) for a tab, chr(13) for a carriage return. You could then use the replace function (http://ideascripting.com/node/71) to replace them such as replace(MyString, chr(11), ",") should replace the any tabes in MyString with the comma.
Hopefully that helps you out a bit, let me know if it works for you.
Unfortunately there is no direct replace in IDEAScript like there is in VBA.
Brian