Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Slick way to remove special char
Message
De
26/03/2008 10:03:02
 
 
À
26/03/2008 10:00:58
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
01305645
Message ID:
01305653
Vues:
12
>>>I have a sp to remove special characters from an input string, and it works fine, but I am wondering if there is a slicker (is that a word?) way to do this. The code is:
>>>
>>>
>>>ALTER PROCEDURE [dbo].[sRemoveSCW]
>>>@StringIn VARCHAR(2000),
>>>@StringOut VARCHAR(2000) OUTPUT
>>>AS
>>>BEGIN
>>>	SET NOCOUNT ON;
>>>
>>>	SET @StringOut = REPLACE(@StringIn, '~', '')
>>>	SET @StringOut = REPLACE(@StringOut, '`', '')
>>>	SET @StringOut = REPLACE(@StringOut, '!', '')
>>>	SET @StringOut = REPLACE(@StringOut, '@', '')
>>>	SET @StringOut = REPLACE(@StringOut, '#', '')
>>>	SET @StringOut = REPLACE(@StringOut, '$', '')
>>>	SET @StringOut = REPLACE(@StringOut, '%', '')
>>>	SET @StringOut = REPLACE(@StringOut, '^', '')
>>>	SET @StringOut = REPLACE(@StringOut, '&', '')
>>>	SET @StringOut = REPLACE(@StringOut, '*', '')
>>>	SET @StringOut = REPLACE(@StringOut, '(', '')
>>>	SET @StringOut = REPLACE(@StringOut, ')', '')
>>>	SET @StringOut = REPLACE(@StringOut, '+', '')
>>>	SET @StringOut = REPLACE(@StringOut, '=', '')
>>>	SET @StringOut = REPLACE(@StringOut, '{', '')
>>>	SET @StringOut = REPLACE(@StringOut, '}', '')
>>>	SET @StringOut = REPLACE(@StringOut, '[', '')
>>>	SET @StringOut = REPLACE(@StringOut, ']', '')
>>>	SET @StringOut = REPLACE(@StringOut, '|', '')
>>>	SET @StringOut = REPLACE(@StringOut, ';', '')
>>>	SET @StringOut = REPLACE(@StringOut, ':', '')
>>>	SET @StringOut = REPLACE(@StringOut, '<', '')
>>>	SET @StringOut = REPLACE(@StringOut, '>', '')
>>>	SET @StringOut = REPLACE(@StringOut, '?', '')
>>>	SET @StringOut = REPLACE(@StringOut, ',', '')
>>>	SET @StringOut = REPLACE(@StringOut, ' ', '')
>>>	SET @StringOut = REPLACE(@StringOut, '/', '')
>>>	SET @StringOut = REPLACE(@StringOut, '\', '')
>>>	SELECT @StringOut
>>>END
>>>
>>>
>>>Any input or comments are appreciated!
>>
>>I don't think there is CHRTRAN in SQL Server <g>
>
>:( Wish there was. SQL 05 has gotten better about some string capabilities, but still has a way to go.

The PATINDEX command can test for items, but I have not figured a way to do the replace, at least not better than the original code.
Thank You

Rollin Burr

Politicians and diapers have one thing in common. They should both be changed regularly, and for the same reason.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform