public static int CountSubString(text textComplet, text subString) { int contador = 0; int pos = 0; text stringT = ""; for (int i = 0, textCompletCount = textComplet.Count; i < textCompletCount; i++) { char caracter = textComplet[i]; if (pos < subString.Length) { if (subString[pos] == caracter) { stringT += caracter; pos++; } else { pos = 0; stringT = ""; } } if (stringT.Equals(subString)) { contador++; stringT = ""; pos = 0; } } return(contador); }
public text SubString(text stringComençament, text stringFi) { text textS = ""; text iniciFi = ""; bool trobatInici = false; bool trobatFi = false; int pos = 0; char caracter; for (int i = 0, maxCount = this.Count; i < maxCount; i++) { caracter = this[i]; if (!trobatInici) { if (pos < stringComençament.Length) { if (stringComençament[pos] == caracter) { iniciFi += caracter; pos++; } else { pos = 0; iniciFi = ""; } } trobatInici = stringComençament.Equals(iniciFi); if (trobatInici) { textS += stringComençament; iniciFi = ""; pos = 0; } } else if (!trobatFi) { textS += caracter; if (pos < stringFi.Length) { if (stringFi[pos] == caracter) { iniciFi += caracter; pos++; } else { pos = 0; iniciFi = ""; } } trobatFi = stringFi.Equals(iniciFi); } } return(textS); }