Título: [RETO] Funcion EntreTextos
Publicado por: 79137913 en 12 Junio 2012, 15:25 pm
HOLA!!! El reto consiste en hacer la version mas rapida de la siguiente funcion: Busca un string entre otros 2 strings. Por ejemplo : Private Sub Form_Load() str1 = "hola franco como andas, hola pepe como andas" str2 = "hola " str3 = " como" Debug.Print EntreTextos(str1, str2, str3) 'imprimira: "franco" 'como veran solo la primera asi que ojo XD End Sub Public Function EntreTextos(Text As String, Text1 As String, Text2 As String) As String EntreTextos = MidB$(Text, InStrB(Text, Text1) + LenB(Text1), InStrB(Text, Text2) - InStrB(Text, Text1) - LenB(Text1)) End Function 'o esta: Public Function EntreTextos(Text As String, Text1 As String, Text2 As String) As String Dim a As Long a = InStrB(Text, Text1) If a Then Dim b As Long b = InStrB(Text, Text2) If b Then Dim c As Long Dim d As Long c = LenB(Text1) d = InStrB(Text, Text2) - a - c If d > 0 Then EntreTextos = MidB$(Text, a + c, d) End If End If End If End Function
yo participo directamente con la que figura alli GRACIAS POR LEER!!!
Título: Re: [RETO] Funcion EntreTextos
Publicado por: Psyke1 en 12 Junio 2012, 16:35 pm
Dejo la mía: Option Explicit 'by Psyke1 Public Static Function TextBTWWords(ByRef sMain As String, ByRef s1 As String, ByRef s2 As String) As String Dim lPos1 As Long Dim lPos2 As Long Dim lStart As Long lPos1 = InStrB(1, sMain, s1, vbBinaryCompare) If lPos1 = 0 Then Exit Function lStart = lPos1 + LenB(s1) lPos2 = InStrB(lStart, sMain, s2, vbBinaryCompare) If lPos2 = 0 Then Exit Function TextBTWWords = MidB$(sMain, lStart, lPos2 - lStart) End Function Private Sub Form_Load() Debug.Print TextBTWWords("qwertysdfcv [raul338 es feo] prueba", "[", "]") Debug.Print TextBTWWords("aitheoiethi[BLABLABLA]taihoithaoihtoea", "(", "]") Debug.Print TextBTWWords("aitheoiethi[BLABLABLA)taihoithaoihtoea", ")", "[") Debug.Print TextBTWWords("qwertysdfcv raul338 es feo] prueba", "[", "]") Debug.Print TextBTWWords("aitheoiet[hi[BLABLABLA]taihoithaoihtoea", "[", "]") End Sub
El domingo pongo mi versión API-Doping, aunque dudo que se pueda hacer más rápida aún... :-\ Demostradme que me equivoco. :rolleyes: DoEvents! :P
|