HOLA!!!
La encontre en un proyecto que estoy desarrollando y por ahi le sirve a alguien.
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
GRACIAS POR LEER!!!
cheee, el hombre rana se habia sacado una igualita a esa.
Creo que era textbetweenwords
'by Mr.Frog™
Public Function TextBetweenWords(ByRef strText$, ByRef strWord1$, ByRef strWord2$) As String
Dim lngPos1&, lngPos2&, lngStart&
lngPos1 = InStr(strText, strWord1)
If lngPos1 Then
lngStart = lngPos1 + LenB(strWord1) \ 2
lngPos2 = InStr(lngStart, strText, strWord2)
If iPosition2 Then
TextBetweenWords = Mid$(strText, lngStart, lngPos2 - lngStart)
End If
End If
HOLA!!!
Ni sabia pero mi funcion es mas rapida y mas corta!
GRACIAS POR LEER!!!
Toma, aquí te dejo un par de errores:
Option Explicit
Private Sub Form_Load()
MsgBox EntreTextos("aitheoiethi[BLABLABLA]taihoithaoihtoea", "(", "]")
MsgBox EntreTextos("aitheoiethi[BLABLABLA)taihoithaoihtoea", ")", "[")
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
Más rápida con cadenas largas habría que verlo. :silbar:
DoEvents! :P
HOLA!!!
No es mi culpa que ingreses mal los conceptos.
Fijate que en el primero no hay (
y en el segundo no existe nada entre ")" y "[" (lo que no quiere decir que exista o no algo entre "[" y ")" )
GRACIAS POR LEER!!!
Hombre, ya sé que ingresé mal, lo hice queriendo. Una función no puede fallar en ningún caso. :rolleyes: En los ejemplos que te puse debería de devolver un String vacío.
Imagina que tengo el HTML de una web, quiero recortar un trozo, han cambiado algo en el code y tu función nos devuelve algo que no es correcto o nos crashea (cómo en el segundo caso). :-(
DoEvents! :P
HOLA!!!
Ok lo hacemos asi
GRACIAS POR LEER!!!
HOLA!!!
Aca tenes la solucion:
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
GRACIAS POR LEER!!!