I try to create a MySQL function to parse a given string into a version I can use in an URL. So I have to eliminate some special characters and I try to do it with a loop to keep the code simple and to not have to specify any character.
My current code is:
DECLARE parsedString VARCHAR(255);
# convert to low chars
SET parsedString = CONVERT(paramString USING latin1);
SET parsedString = LOWER(parsedString);
# replace chars with A
SET @x = 223;
charReplaceA: WHILE @x <= 229 DO
SET @x = @x + 1;
SET parsedString = REPLACE (parsedString, CHAR(@x USING ASCII), 'a');
END WHILE charReplaceA;
# convert to utf8 and return
RETURN CONVERT(parsedString USING utf8);
If I try to use my code it doesn't work. Somehow it doesn't recognize the CHAR(@x USING ASCII) part.
SELECT urlParser('aäeucn');
returns
aäeucn
If I change my code to
SET parsedString = REPLACE (parsedString, 'ä', 'a');
it somehow works and returns
aaeucn
Does anyone have any idea how to use REPLACE() with CHAR()? I don't want to specify any possible character.