[Closed] How to check if string is "safe"?
The user will input a name for a folder I create. So I need a way to check if the string is safe.
So no ¤%&”#% signs and no spaces either. What would be the best way to do this in max?
I’m thinking look at every char and do a comparison to every letter from a-z if it’s not one of them it won’t allow the letter. But this sounds uneffective and not so much fun!
Does anyone have any better ideas?
/Andreas
you could use the filterString function, just put all characters that are not allowed into the filterpattern and you will get an array of strings, then you just have to put this back together to one string.
Hmm, wouldn’t it be better to look for those chars that are allowed. Basically I should only allow a-Z and a few chars like _ and – since i want the string to be web-safe. (Hey I’m creating a website from inside of max!)
If I want to check for all letters that are not allowed I have to put in zillions of chars.
/Andreas
yes, this way makes more sence. i know i also have had this problem some time ago, but i just can’t remember how i solved it and in which script i did it, i’ll search around a bit
this website thing is really great, i wish more tools would have features like that!! also these preview thumbnails are great, i am thinking of adding something like this in some of my scripts, previews for skeletons or so… currently trying to add a 3d preview in a seperate windowed 3d view, this keeps me pretty busy, it’s a shame that you couldn’t just create a windowed viewport in max…
I think I know the best way to do this now. Just check if every char is bigger than ‘a’ and smaller than ‘Z’ and also bigger than 0 and smaller than 9. that should work well and be fast. I can also add ‘_’ and ‘-’ too.
Glad you like the website thing, I wasn’t sure I was wasting my time. It’s pretty cool, I will upload one website that shows how it works for CGTalk today or tomorrow I think. It’s really cool that you can just take snapshots by a keypress of the viewport and even let it automaticaly take snapshots ever once in a while, and that it keeps all the renders that you have made.
One thing I’m considering adding that will NOT be fun is that the thumbnails can be displayed in a table. So 4 thumbs and note text next to each other. The coding for that sounds less than fun in MaxScript though, since I will have to resize the table dynamically (but it would be very nice!)
Yea, windows in max, hehe, it’s pretty silly that you can’t do this. At least you can resize the viewports these days, remember max-pre-version4? Fixed layout…
/Andreas
Here you go!
3 functions. On checks if input string is in numbers, the other if it’s letters and the last one if it’s either numbers or letters. i’m positive there is a more elegant way to solve this, but it works and I have little time to compress the code. It should be possible to just do one function that returns if it’s numbers, letters or num or letters instead. if the string is undefined or empty it will return false.
/Andreas
[size=1]fn FW_IsNumeric tempText=
(
isOk=true; i=1
if tempText!=undefined then
(
if tempText==”” then isOk=false
while i<=tempText.count and isOk do
(
if (tempText[i]<“0” or tempText[i]>“9”) then (isOk=false)
i=i+1
)
)
else isOk=false
return isOk
)
fn FW_IsLetters tempText=
(
isOk=true; i=1
if tempText!=undefined then
(
if tempText==”” then isOk=false
while i<=tempText.count and isOk do
(
if (tempText[i]<“a” or tempText[i]>“z”) then
if (tempText[i]<“A” or tempText[i]>“Z”) then (isOk=false)
if tempText[i]==”_” or tempText[i]==”-” then isOk=true
i=i+1
)
)
else isOk=false
return isOk
)
fn FW_IsLettersOrNumeric tempText=
(
isOk=true; i=1
if tempText!=undefined then
(
if tempText==”” then isOk=false
while i<=tempText.count and isOk do
(
if (tempText[i]<“a” or tempText[i]>“z”) then
if (tempText[i]<“A” or tempText[i]>“Z”) then
if (tempText[i]<“0” or tempText[i]>“9”) then (isOk=false)
if tempText[i]==”_” or tempText[i]==”-” then isOk=true
i=i+1
)
)
else isOk=false
return isOk
)
[/size]
cool i am sure i will need this sooner or later!!
about your problem with the tables and thumbnails, have you thought about using an activeX control for this? so you could display a website inside your script or something else. haven’t done much with activeX upto now, but i guess it is a pretty powerful addition for an user interface…
Yea, I thought about it briefly, not really for this function. I just use the shell command to open the site if the user presses “All”, then IE opens with the thumbnails, it works good.
However it would be very good if I could check things on the internet with the program. Do you know how to do that?
Basically I want to automatically check if there is a new version available.
/Andreas
hmm, i don’t think you can do this in maxscript directly, but there might be some tools around which can do this and which you can start from within your script, all you need is something that connects to a site, retrieves information and send it back to you (or is written to file that you can check from maxscript).
no idea on where to search for such a tool though…
Ok, hmm I guess I’m on my own with this one though. What I could do is of course to create an extention to MaxScript, and do it in c++ instead. But honestly I never tried retrieving anything from the internet with c++ so I’m sure that will be not-so-great to figure out. Also I can imagine that peoples antivirus programs and wirewalls may get upset if I try to retrieve info. Perhaps it’s better to just have a link in the program to uploads, but I really like to keep updates as smooth as possible, since I lack this in many other programs. I love the: “there is a new update available, do you want to update now?”
I don’t like these though:” You are trying to install 1.037 english version, but your language is spanish, do you want to revert to 1.027 english version? You also have to install microsoft dhh.dll and remember to not have any antivirus programs on! And bzzzz System Exception, the program has terminated your hdd…”
I say more power to the user and less boring installations
/Andreas
If you only want to test if a string is valid do this:
validString = “abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ”
checkString = “ThisIsAValidString”
s = filterstring checkString validString
if s.count == 0 then validString isn’t valid
Just add more valid characters to validString.