private static string RemoverParentesis(string cad, CleanExtraOptions op) { if ((op & CleanExtraOptions.opRemoverBloqueParentesisFinal) != 0) { if (cad.EndsWith(")")) { int n = cad.LastIndexOf("("); cad = cad.Substring(0, n).Trim(); } } if ((op & CleanExtraOptions.opRemoverParentesisInicioFin) != 0) { { if (cad.EndsWith(")")) { cad = cad.Substring(0, cad.Length - 1); } if (cad.StartsWith("(")) { cad = cad.Substring(1); } } } return(cad); }
private static string RemoverComillas(string cad, CleanExtraOptions op) { if ((op & CleanExtraOptions.opRemoverComillas) != 0) { if ((cad.EndsWith("\"") || cad.EndsWith("“") || cad.EndsWith("”") || cad.EndsWith("'") || cad.EndsWith(""") || cad.EndsWith("“") || cad.EndsWith("”") || cad.EndsWith("’")) && (cad.StartsWith("\"") || cad.StartsWith("”") || cad.StartsWith("“") || cad.StartsWith("'") || cad.EndsWith(""") || cad.EndsWith("“") || cad.EndsWith("”") || cad.StartsWith("‘"))) { cad = cad.Substring(0, cad.Length - 1); if (cad.Length > 0) { cad = cad.Substring(1); } } } return(cad); }
public static string CleanHtmlTextSpaces(string cad, CleanExtraOptions op = CleanExtraOptions.opNinguna) { for (int n = 0; n < 2; n++) { //0x160 cad = cad.Replace(" ", " "); cad = cad.Replace(" ", " "); cad = cad.Replace("\n", " "); cad = cad.Replace("–", "-"); cad = cad.Replace("\t", " "); cad = cad.Replace("\r", " "); cad = System.Web.HttpUtility.HtmlDecode(cad); cad = RemoverDobleEspacio(cad); cad = cad.Trim(); // opRemoverDosPuntosIniciales if ((op & CleanExtraOptions.opRemoverDosPuntosIniciales) != 0) { if (cad.StartsWith(":")) { cad = cad.Substring(1); } } // opRemoverDosPuntosFinales if ((op & CleanExtraOptions.opRemoverDosPuntosFinales) != 0) { if (cad.EndsWith(":")) { cad = cad.Substring(0, cad.Length - 1); } } // opRemoverDosPuntosFinales if ((op & CleanExtraOptions.opRemoverComaFinal) != 0) { if (cad.EndsWith(",")) { cad = cad.Substring(0, cad.Length - 1); } } // opRemoverPuntoInicial if ((op & CleanExtraOptions.opRemoverPuntoInicial) != 0) { if (cad.StartsWith(".")) { cad = cad.Substring(1); } } // opRemoverPuntoFinal if ((op & CleanExtraOptions.opRemoverPuntoFinal) != 0) { if (cad.EndsWith(".")) { cad = cad.Substring(0, cad.Length - 1); } } // opRemoverComillas cad = RemoverComillas(cad, op); // opRemoverBloqueParentesisFinal cad = RemoverParentesis(cad, op); // opRemoverComillas cad = RemoverComillas(cad, op); // opRemoverMesaDosPuntos if ((op & CleanExtraOptions.opRemoverMesaDosPuntos) != 0) { if (cad.StartsWith("Mesa:")) { cad = cad.Substring(5); } } if ((op & CleanExtraOptions.opKeepBRAsNL) != 0) { cad = cad.Replace("<br>", "\r\n"); cad = cad.Replace("<br/>", "\r\n"); cad = cad.Replace("<BR>", "\r\n"); } } return(cad); }