Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
ReplaceNotExpectedCharacters
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { Console.WriteLine("========== NOME ========="); var nomeEntrada = "JOÃO ',.- DA SILVA"; var nomeSaida = "JOÃO DA SILVA"; var nomeTratado = Utilities.ReplaceNotExpectedCharacters(nomeEntrada, @"[^a-zA-ZàèìòùÀÈÌÒÙáéíóúýÁÉÍÓÚÝâêîôûÂÊÎÔÛãñõÃÑÕäëïöüÿÄËÏÖÜŸçÇ\ ]", " "); Console.WriteLine("String Original: {0}", nomeEntrada); Console.WriteLine("String tratada : {0}", nomeTratado); Console.WriteLine(nomeTratado == nomeSaida); Console.WriteLine("========== CNPJ/CPF ========="); var cpfEntrada = "423.489.300-56"; var cpfSaida = "42348930056"; var cpfTratado = Utilities.ReplaceNotExpectedCharacters(cpfEntrada, @"[^\d+]", ""); Console.WriteLine("String Original: {0}", cpfEntrada); Console.WriteLine("String tratada : {0}", cpfTratado); Console.WriteLine(cpfTratado == cpfSaida); Console.WriteLine("========== Date (yyyy-MM-dd) ========="); var dataEntrada = "1988/08/23"; var dataSaida = "1988-08-23"; var dataTratado = Utilities.ReplaceNotExpectedCharacters(dataEntrada, @"[^\d+]", ""); dataTratado = dataTratado.Insert(4,"-"); dataTratado = dataTratado.Insert(7,"-"); Console.WriteLine("String Original: {0}", dataEntrada); Console.WriteLine("String tratada : {0}", dataTratado); Console.WriteLine(dataTratado == dataSaida); Console.WriteLine("========== Email ========="); var emailEntrada = "joão '.silva&@xxxbrasil.com"; var emailSaida = "joao.silva@xxxbrasil.com"; var emailTratado = Utilities.ReplaceNotExpectedCharacters(emailEntrada, @"[^A-Z0-9._%+-+@]", ""); Console.WriteLine("String Original: {0}", emailEntrada); Console.WriteLine("String tratada : {0}", emailTratado); Console.WriteLine(emailTratado == emailSaida); } } public static class Utilities { /// <summary> /// Replaces not expected characters. /// </summary> /// <param name="text"> The text.</param> /// <param name="allowedPattern"> The allowed pattern in Regex format, expect them wrapped in brackets</param> /// <param name="replacement"> The replacement.</param> /// <returns></returns> public static string ReplaceNotExpectedCharacters(this string text, string allowedPattern, string replacement) { //allowedPattern = allowedPattern.StripBrackets("[", "]"); //[^ ] at the start of a character class negates it - it matches characters not in the class. var result = Regex.Replace(text, allowedPattern, replacement); return Regex.Replace(result, "[ ]{2,}", " ").Trim(); //returns result free of negated chars } } }
run
|
edit
|
history
|
help
0
sdfsdfs
Problem3 Binary
WATCH! Malignant (2021) Online Movie Full HD For Free Download
c++
C++
array integration
String Factorial Sorter
("Hello, world!\n");
Flipping a bit
Dependency Injection