Wednesday, September 13, 2017

Replace Special Characters with Hyphen in a String


String value = 'tstu# is @ ' d ,s . "; dfs:';

value = value.replaceAll('[|,|.|\\,||"||:|~|!|@|#|$|%|^|&|*|_|+|=|<|>|?|\\(|\\)|\\{|\\}|\\;|\\\'"]', '-');

debug value: tstu is d s dfs: