What is the best way to validate a WebService call? I explain: I have a WebService that has as Request a String of varying size and that returns the same formatted string, eg:
Input String:
"ST STN, SET J, * STORES T-40 / T41, - TER-REO, SHOPPING & BOULEVARD KM 28,5 VALUE 450.00 CENTRAL. "
And that should return the String in the following format:
"ST STN CONJUNTO J LOJAS T40 T41 TERREO SHOPPING AND BOULEVARD KM 28,5 450.00 CENTRAL
Note: Decimal fields preserve Point and Comma .
That is, remove all Special Characters with EXCEPTION where Decimal Values , such as 28.5 and 450.00. p>
I have tried to do with Regex.Replace but without success and I am doing with Replace native C # , however with Replace it gets very complex as follows:
Here it replaces some characters (problem does not cover all characters):
string _texto = pTexto.Trim().Replace("S/A","SA").Replace("s.a.", "SA").Replace("S.A.","SA").Replace("S A", "SA").Replace("'","")
.Replace("-", " ").Replace("&", "E").ToUpper().Replace("(","")
.Replace(")","") .Replace("/", " ").Trim().Replace(";", "").Replace("N/C", "NC").Replace("\"","")
.Replace("*","").Replace("+", "");
And with Regex I could not because Everyone removed the accents and characters of the sentence, the values Decimals lose the Comma or Point
String padrao = @"(?i)(,|.)?[^A-Z0-9]\s";
String padrao = @"(?i)[^0-9A-Z]\s]";
Regex rg = new Regex(_texto, " ");
var arrayTexto = resultado.Normalize(NormalizationForm.Formd).toCharArray();
foreach(char letter in arrayTexto) {
if (CharUnicodeInfo.GetUnicodeCategory(letter) != UnicodeCategory.NonSpacingMark) sb.Append(letter);
}
What is the best way to validate this string?