How to validate data entry from a web service?

Asked

Viewed 162 times

0

What is the best way to validate a Webservice call? I explain: I have a Webservice that has as Request a String of varied size and that returns the same string Formatted, example:

Input string:

"ST STN, CONJUNTO J, * LOJAS T-40 /T41, - TER-REO, SHOPPING & BOULEVARD KM 28.5 VALUE 450.00 CENTRAL."

And that you must return the String in the following format:

"ST STN SET J STORES T40 T41 TERREO SHOPPING AND BOULEVARD KM 28,5 450.00 CENTRAL"

Note: Decimal fields preserve the Dot and Comma.

That is, remove all Special Characters with EXCEPTION wherever Decimal Values, such as 28.5 and 450.00.

I’ve tried to do with Regex.Replace. but without success and I’m doing it with Replace native to C# , but with Replace it is very complex as a section below, example:

Here overwrites 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 couldn’t, because I’m retiring all the accents and characters of the sentence, the values Decimal lose the Comma or the Dot

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?

1 answer

0

Instead of receiving a single string, "break" it into several parts, so you can use a logic to remove the characters from the first part :

"ST STN, CONJUNTO J, * LOJAS T-40 /T41, - TER-REO, SHOPPING & BOULEVARD";

Then another logic to check the parts :

"KM 28,5" "VALOR 450.00 CENTRAL"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.