PDA

View Full Version : Detect Special Character ??



RizlaUK
03-28-2008, 01:54 PM
i need a way of detecting a special character in a string of text

eg:

i have a mp3 file with the name "Sweet Family Attitude - 8 Days A Week (10° Below Vs X.Men-Mix).mp3", the char marked in red is the troublesome one

it seems that my audio engine dosent like special character, it will not play the file or read its id3 tags and i get a error report from the ocx i am useing saying "invalid file", but if i change the name or remove the special char then it works ok but i want to be able to track the fault in the invalid file and inform the user to change the filename (or remove special char)

any ideas or pointers

Worm
03-28-2008, 02:29 PM
You can search for extended characters by using its ASCII value.



if String.Find(MP3Name, "\248") ~= -1 then
--found a bad character
end

holtgrewe
03-28-2008, 02:44 PM
Rizla
This is pretty lame, but it works...
just editted ranges of ascii characters.


s1 = Input.GetText("Input1")
s2=""
sLen = String.Length(s1)
for x = 1, sLen do
if (String.Mid(s1, x, 1)) == " " or
(String.Mid(s1, x, 1)) == "." or
(String.Mid(s1, x, 1)) == "-" or
((String.Mid(s1, x, 1)) > "/" and (String.Mid(s1, x, 1)) < ":") or
((String.Mid(s1, x, 1)) > "@" and (String.Mid(s1, x, 1)) < "[") or
((String.Mid(s1, x, 1)) > "`" and (String.Mid(s1, x, 1)) < "{")
then

s2=s2 .. String.Mid(s1,x,1)
else
s2=s2 .. "-"
end
end

Input.SetText("Input2", s2)

azmanar
03-28-2008, 02:56 PM
Riz,

I suggest u use the LUA regex to detect all sorts of special characters.

RizlaUK
03-28-2008, 03:12 PM
thanks guys, i was hoping there was a easy way or ready made dll to catch all special chrs.

guess i'll have to get busy then, think ill make a dll, for reuseabilty in other apps


EDIT:


I suggest u use the LUA regex to detect all sorts of special characters.

iv been lead to beleave regex is a little complecated, i think i will have a quick research on the subject and see what i can do